2015-06-25 11:07:55 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
2015-09-12 19:57:12 -04:00
|
|
|
SCRIPTDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
2015-09-12 20:08:01 -04:00
|
|
|
source $SCRIPTDIR/common.sh
|
2015-09-12 19:57:12 -04:00
|
|
|
|
2015-10-27 21:06:06 -04:00
|
|
|
##############################################################
|
|
|
|
# main
|
|
|
|
##############################################################
|
2016-01-02 05:29:53 -05:00
|
|
|
while getopts "flpu:" opt; do
|
2015-10-27 21:06:06 -04:00
|
|
|
case $opt in
|
|
|
|
f)
|
|
|
|
echo "fastboot enabled"
|
|
|
|
METHOD=fastboot
|
|
|
|
;;
|
|
|
|
l)
|
|
|
|
echo "factory mode remain in u-boot after flashing"
|
|
|
|
AFTER_FLASHING=loop
|
|
|
|
;;
|
|
|
|
u)
|
|
|
|
BUILDROOT_OUTPUT_DIR="${OPTARG}"
|
|
|
|
;;
|
2016-01-02 05:29:53 -05:00
|
|
|
p)
|
|
|
|
POCKET_CHIP=true
|
|
|
|
;;
|
2015-10-27 21:06:06 -04:00
|
|
|
\?)
|
|
|
|
echo "Invalid option: -$OPTARG" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "BUILDROOT_OUTPUT_DIR = $BUILDROOT_OUTPUT_DIR"
|
|
|
|
|
2015-09-12 19:57:12 -04:00
|
|
|
FEL=fel
|
|
|
|
|
2015-10-21 17:26:59 -04:00
|
|
|
METHOD=${METHOD:-fel}
|
2015-10-27 21:06:06 -04:00
|
|
|
AFTER_FLASHING=${AFTER_FLASHING:-wait}
|
2015-10-21 17:26:59 -04:00
|
|
|
|
2015-06-25 11:07:55 -04:00
|
|
|
|
|
|
|
NAND_ERASE_BB=false
|
|
|
|
if [ "$1" == "erase-bb" ]; then
|
|
|
|
NAND_ERASE_BB=true
|
|
|
|
fi
|
|
|
|
|
2015-07-01 10:52:20 -04:00
|
|
|
PATH=$PATH:$BUILDROOT_OUTPUT_DIR/host/usr/bin
|
2015-09-12 19:57:12 -04:00
|
|
|
TMPDIR=`mktemp -d -t chipflashXXXXXX`
|
2015-10-27 21:06:06 -04:00
|
|
|
PADDED_SPL="${BUILDROOT_OUTPUT_DIR}/images/sunxi-spl-with-ecc.bin"
|
2015-06-25 11:07:55 -04:00
|
|
|
PADDED_SPL_SIZE=0
|
2015-06-25 11:59:26 -04:00
|
|
|
UBOOT_SCRIPT="$TMPDIR/uboot.scr"
|
2015-06-25 11:07:55 -04:00
|
|
|
UBOOT_SCRIPT_MEM_ADDR=0x43100000
|
2015-06-25 11:59:26 -04:00
|
|
|
UBOOT_SCRIPT_SRC="$TMPDIR/uboot.cmds"
|
2015-06-25 12:14:13 -04:00
|
|
|
SPL="$BUILDROOT_OUTPUT_DIR/images/sunxi-spl.bin"
|
2015-06-25 11:07:55 -04:00
|
|
|
SPL_MEM_ADDR=0x43000000
|
2015-06-25 12:14:13 -04:00
|
|
|
UBOOT="$BUILDROOT_OUTPUT_DIR/images/u-boot-dtb.bin"
|
2015-06-25 11:59:26 -04:00
|
|
|
PADDED_UBOOT="$TMPDIR/padded-uboot"
|
2016-01-09 21:35:33 -05:00
|
|
|
PADDED_UBOOT_SIZE=0x400000
|
2015-06-25 11:07:55 -04:00
|
|
|
UBOOT_MEM_ADDR=0x4a000000
|
2015-06-25 12:14:13 -04:00
|
|
|
UBI="$BUILDROOT_OUTPUT_DIR/images/rootfs.ubi"
|
2015-10-30 20:12:09 -04:00
|
|
|
SPARSE_UBI="${TMPDIR}/rootfs.ubi.sparse"
|
2015-08-26 20:11:39 -04:00
|
|
|
UBI_MEM_ADDR=0x4b000000
|
2015-09-12 19:57:12 -04:00
|
|
|
|
|
|
|
UBI_SIZE=`filesize $UBI | xargs printf "0x%08x"`
|
2015-10-21 17:26:59 -04:00
|
|
|
PAGE_SIZE=16384
|
|
|
|
OOB_SIZE=1664
|
2015-06-25 11:07:55 -04:00
|
|
|
|
|
|
|
prepare_images() {
|
2015-10-27 21:06:06 -04:00
|
|
|
#PADDED_SPL_SIZE in pages
|
|
|
|
if [[ ! -e "${PADDED_SPL}" ]]; then
|
|
|
|
echo "ERROR: can not read ${PADDED_SPL}"
|
|
|
|
exit 1
|
2015-10-21 17:26:59 -04:00
|
|
|
fi
|
|
|
|
|
2015-10-27 21:06:06 -04:00
|
|
|
PADDED_SPL_SIZE=$(filesize "${PADDED_SPL}")
|
2015-10-21 17:26:59 -04:00
|
|
|
PADDED_SPL_SIZE=$(($PADDED_SPL_SIZE / ($PAGE_SIZE + $OOB_SIZE)))
|
|
|
|
PADDED_SPL_SIZE=$(echo $PADDED_SPL_SIZE | xargs printf "0x%08x")
|
|
|
|
echo "PADDED_SPL_SIZE=$PADDED_SPL_SIZE"
|
2015-06-25 11:07:55 -04:00
|
|
|
|
2015-06-25 11:56:46 -04:00
|
|
|
# Align the u-boot image on a page boundary
|
2016-01-09 21:35:33 -05:00
|
|
|
dd if="$UBOOT" of="$PADDED_UBOOT" bs=4M conv=sync
|
2015-10-23 19:43:53 -04:00
|
|
|
UBOOT_SIZE=`filesize "$PADDED_UBOOT" | xargs printf "0x%08x"`
|
2015-10-27 21:06:06 -04:00
|
|
|
echo "UBOOT_SIZE=${UBOOT_SIZE}"
|
|
|
|
echo "PADDED_UBOOT_SIZE=${PADDED_UBOOT_SIZE}"
|
2015-10-23 19:43:53 -04:00
|
|
|
dd if=/dev/urandom of="$PADDED_UBOOT" seek=$((UBOOT_SIZE / 0x4000)) bs=16k count=$(((PADDED_UBOOT_SIZE - UBOOT_SIZE) / 0x4000))
|
2015-06-25 11:07:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
prepare_uboot_script() {
|
|
|
|
if [ "$NAND_ERASE_BB" = true ] ; then
|
2015-10-23 19:43:53 -04:00
|
|
|
echo "nand scrub -y 0x0 0x200000000" > "${UBOOT_SCRIPT_SRC}"
|
2015-06-25 11:07:55 -04:00
|
|
|
else
|
2015-10-23 19:43:53 -04:00
|
|
|
echo "nand erase 0x0 0x200000000" > "${UBOOT_SCRIPT_SRC}"
|
2015-06-25 11:07:55 -04:00
|
|
|
fi
|
2015-10-30 20:12:09 -04:00
|
|
|
|
|
|
|
echo "echo nand write.raw.noverify $SPL_MEM_ADDR 0x0 $PADDED_SPL_SIZE" >> "${UBOOT_SCRIPT_SRC}"
|
|
|
|
echo "nand write.raw.noverify $SPL_MEM_ADDR 0x0 $PADDED_SPL_SIZE" >> "${UBOOT_SCRIPT_SRC}"
|
|
|
|
echo "echo nand write.raw.noverify $SPL_MEM_ADDR 0x400000 $PADDED_SPL_SIZE" >> "${UBOOT_SCRIPT_SRC}"
|
|
|
|
echo "nand write.raw.noverify $SPL_MEM_ADDR 0x400000 $PADDED_SPL_SIZE" >> "${UBOOT_SCRIPT_SRC}"
|
|
|
|
|
2015-10-23 19:43:53 -04:00
|
|
|
echo "nand write $UBOOT_MEM_ADDR 0x800000 $PADDED_UBOOT_SIZE" >> "${UBOOT_SCRIPT_SRC}"
|
|
|
|
echo "setenv bootargs root=ubi0:rootfs rootfstype=ubifs rw earlyprintk ubi.mtd=4" >> "${UBOOT_SCRIPT_SRC}"
|
2016-01-02 05:29:53 -05:00
|
|
|
echo "setenv bootcmd 'gpio set PB2; if test -n \${fel_booted} && test -n \${scriptaddr}; then echo '(FEL boot)'; source \${scriptaddr}; fi; mtdparts; ubi part UBI; ubifsmount ubi0:rootfs; ubifsload \$fdt_addr_r /boot/sun5i-r8-chip.dtb; ubifsload \$kernel_addr_r /boot/zImage; bootz \$kernel_addr_r - \$fdt_addr_r'" >> "${UBOOT_SCRIPT_SRC}"
|
2015-11-08 02:24:07 -05:00
|
|
|
echo "setenv fel_booted 0" >> "${UBOOT_SCRIPT_SRC}"
|
2015-11-10 22:10:25 -05:00
|
|
|
|
2015-11-11 21:58:01 -05:00
|
|
|
echo "echo Enabling Splash" >> "${UBOOT_SCRIPT_SRC}"
|
2015-11-10 22:10:25 -05:00
|
|
|
echo "setenv stdout serial" >> "${UBOOT_SCRIPT_SRC}"
|
|
|
|
echo "setenv stderr serial" >> "${UBOOT_SCRIPT_SRC}"
|
|
|
|
echo "setenv splashpos m,m" >> "${UBOOT_SCRIPT_SRC}"
|
|
|
|
|
2015-11-11 21:58:01 -05:00
|
|
|
echo "echo Configuring Video Mode"
|
2016-01-02 05:29:53 -05:00
|
|
|
if [[ "${POCKET_CHIP}" == "true" ]]; then
|
|
|
|
echo "setenv video-mode" >> "${UBOOT_SCRIPT_SRC}"
|
|
|
|
else
|
|
|
|
echo "setenv video-mode sunxi:640x480-24@60,monitor=composite-ntsc,overscan_x=40,overscan_y=20" >> "${UBOOT_SCRIPT_SRC}"
|
|
|
|
fi
|
2015-11-11 21:58:01 -05:00
|
|
|
|
2015-11-10 22:10:25 -05:00
|
|
|
echo "saveenv" >> "${UBOOT_SCRIPT_SRC}"
|
2015-09-12 20:16:25 -04:00
|
|
|
|
2015-10-21 17:26:59 -04:00
|
|
|
if [[ "${METHOD}" == "fel" ]]; then
|
2015-10-30 20:12:09 -04:00
|
|
|
echo "nand write.slc-mode.trimffs $UBI_MEM_ADDR 0x1000000 $UBI_SIZE" >> "${UBOOT_SCRIPT_SRC}"
|
2015-10-23 19:43:53 -04:00
|
|
|
echo "mw \${scriptaddr} 0x0" >> "${UBOOT_SCRIPT_SRC}"
|
2015-10-21 17:26:59 -04:00
|
|
|
else
|
2015-10-23 19:43:53 -04:00
|
|
|
echo "echo going to fastboot mode" >>"${UBOOT_SCRIPT_SRC}"
|
2015-10-30 20:12:09 -04:00
|
|
|
echo "fastboot 0" >>"${UBOOT_SCRIPT_SRC}"
|
2015-10-23 20:00:00 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "${AFTER_FLASHING}" == "boot" ]]; then
|
2015-10-23 19:43:53 -04:00
|
|
|
echo "echo " >>"${UBOOT_SCRIPT_SRC}"
|
|
|
|
echo "echo *****************[ BOOT ]*****************" >>"${UBOOT_SCRIPT_SRC}"
|
|
|
|
echo "echo " >>"${UBOOT_SCRIPT_SRC}"
|
2015-10-23 20:00:00 -04:00
|
|
|
echo "boot" >> "${UBOOT_SCRIPT_SRC}"
|
|
|
|
else
|
2015-10-23 19:43:53 -04:00
|
|
|
echo "echo " >>"${UBOOT_SCRIPT_SRC}"
|
2015-10-23 20:00:00 -04:00
|
|
|
echo "echo *****************[ FLASHING DONE ]*****************" >>"${UBOOT_SCRIPT_SRC}"
|
|
|
|
echo "echo " >>"${UBOOT_SCRIPT_SRC}"
|
2016-01-15 20:31:03 -05:00
|
|
|
if [[ "${METHOD}" == "fel" ]]; then
|
|
|
|
echo "reset"
|
|
|
|
else
|
|
|
|
echo "while true; do; sleep 10; done;" >>"${UBOOT_SCRIPT_SRC}"
|
|
|
|
fi
|
2015-10-21 17:26:59 -04:00
|
|
|
fi
|
2015-06-25 11:07:55 -04:00
|
|
|
|
2015-10-23 19:43:53 -04:00
|
|
|
mkimage -A arm -T script -C none -n "flash CHIP" -d "${UBOOT_SCRIPT_SRC}" "${UBOOT_SCRIPT}"
|
2015-06-25 11:07:55 -04:00
|
|
|
}
|
|
|
|
|
2015-11-09 08:54:54 -05:00
|
|
|
assert_error() {
|
|
|
|
ERR=$?
|
|
|
|
ERRCODE=$1
|
|
|
|
if [ "${ERR}" != "0" ]; then
|
|
|
|
if [ -z "${ERR}" ]; then
|
|
|
|
exit ${ERR}
|
2015-11-09 09:12:32 -05:00
|
|
|
else
|
|
|
|
exit ${ERRCODE}
|
2015-11-09 08:54:54 -05:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
2015-10-21 17:26:59 -04:00
|
|
|
|
2015-06-25 11:07:55 -04:00
|
|
|
echo == preparing images ==
|
|
|
|
prepare_images
|
|
|
|
prepare_uboot_script
|
|
|
|
|
|
|
|
echo == upload the SPL to SRAM and execute it ==
|
2015-10-21 17:26:59 -04:00
|
|
|
if ! wait_for_fel; then
|
|
|
|
echo "ERROR: please make sure CHIP is connected and jumpered in FEL mode"
|
|
|
|
fi
|
2015-10-23 19:43:53 -04:00
|
|
|
${FEL} spl "${SPL}"
|
2015-11-09 08:54:54 -05:00
|
|
|
assert_error 128
|
2015-06-25 11:07:55 -04:00
|
|
|
|
|
|
|
sleep 1 # wait for DRAM initialization to complete
|
|
|
|
|
2015-10-21 17:26:59 -04:00
|
|
|
echo == upload spl ==
|
2015-10-27 21:06:06 -04:00
|
|
|
${FEL} write $SPL_MEM_ADDR "${PADDED_SPL}" || ( echo "ERROR: could not write ${PADDED_SPL}" && exit $? )
|
2015-11-09 08:54:54 -05:00
|
|
|
assert_error 129
|
2015-10-21 17:26:59 -04:00
|
|
|
|
|
|
|
echo == upload u-boot ==
|
2015-10-27 21:06:06 -04:00
|
|
|
${FEL} write $UBOOT_MEM_ADDR "${PADDED_UBOOT}" || ( echo "ERROR: could not write ${PADDED_UBOOT}" && exit $? )
|
2015-11-09 08:54:54 -05:00
|
|
|
assert_error 130
|
2015-10-21 17:26:59 -04:00
|
|
|
|
|
|
|
echo == upload u-boot script ==
|
2015-10-27 21:06:06 -04:00
|
|
|
${FEL} write $UBOOT_SCRIPT_MEM_ADDR "${UBOOT_SCRIPT}" || ( echo "ERROR: could not write ${UBOOT_SCRIPT}" && exit $? )
|
2015-11-09 08:54:54 -05:00
|
|
|
assert_error 131
|
2015-06-25 11:07:55 -04:00
|
|
|
|
2015-10-21 17:26:59 -04:00
|
|
|
if [[ "${METHOD}" == "fel" ]]; then
|
2015-11-09 08:54:54 -05:00
|
|
|
echo == upload ubi ==
|
|
|
|
${FEL} --progress write $UBI_MEM_ADDR "${UBI}"
|
2015-10-21 17:26:59 -04:00
|
|
|
|
2015-11-09 08:54:54 -05:00
|
|
|
echo == execute the main u-boot binary ==
|
|
|
|
${FEL} exe $UBOOT_MEM_ADDR
|
2015-10-21 17:26:59 -04:00
|
|
|
|
2015-11-09 08:54:54 -05:00
|
|
|
echo == write ubi ==
|
2015-10-21 17:26:59 -04:00
|
|
|
else
|
2015-11-09 08:54:54 -05:00
|
|
|
echo == execute the main u-boot binary ==
|
|
|
|
${FEL} exe $UBOOT_MEM_ADDR
|
|
|
|
assert_error 132
|
|
|
|
|
|
|
|
echo == creating sparse image ==
|
|
|
|
img2simg ${UBI} ${SPARSE_UBI} $((2*1024*1024))
|
|
|
|
assert_error 133
|
|
|
|
|
|
|
|
echo == waiting for fastboot ==
|
|
|
|
if wait_for_fastboot; then
|
|
|
|
fastboot -i 0x1f3a -u flash UBI ${SPARSE_UBI}
|
|
|
|
assert_error 134
|
|
|
|
|
|
|
|
fastboot -i 0x1f3a continue
|
|
|
|
assert_error 135
|
|
|
|
else
|
|
|
|
rm -rf "${TMPDIR}"
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-10-21 17:26:59 -04:00
|
|
|
fi
|
|
|
|
|
2016-01-15 20:31:03 -05:00
|
|
|
if [[ "${METHOD}" == "fel" ]]; then
|
|
|
|
if ! wait_for_linuxboot; then
|
|
|
|
echo "ERROR: could not flash":
|
2016-02-15 19:12:27 -05:00
|
|
|
rm -rf ${TMPDIR}
|
2016-01-15 20:31:03 -05:00
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
${SCRIPTDIR}/verify.sh
|
|
|
|
fi
|
|
|
|
fi
|
2015-10-23 19:43:53 -04:00
|
|
|
rm -rf "${TMPDIR}"
|
2016-09-11 06:16:08 -04:00
|
|
|
|
|
|
|
ready_to_roll
|
|
|
|
|