Merge branch 'chip/next' into chip/stable

chip/stable
Alex Kaplan 7 years ago
commit 23cde3864c
  1. 2
      chip-fel-fastboot.sh
  2. 168
      chip-fel-flash.sh
  3. 279
      chip-flash
  4. 50
      chip-update-firmware.sh
  5. 5
      common.sh

@ -79,7 +79,7 @@ prepare_uboot_script() {
echo "saveenv" >> "${UBOOT_SCRIPT_SRC}"
echo "echo going to fastboot mode" >>"${UBOOT_SCRIPT_SRC}"
echo "fastboot" >>"${UBOOT_SCRIPT_SRC}"
echo "fastboot 0" >>"${UBOOT_SCRIPT_SRC}"
echo "echo " >>"${UBOOT_SCRIPT_SRC}"
echo "echo *****************[ BOOT ]*****************" >>"${UBOOT_SCRIPT_SRC}"
echo "echo " >>"${UBOOT_SCRIPT_SRC}"

@ -3,12 +3,36 @@
SCRIPTDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source $SCRIPTDIR/common.sh
##############################################################
# main
##############################################################
while getopts "flu:" opt; do
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}"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
echo "BUILDROOT_OUTPUT_DIR = $BUILDROOT_OUTPUT_DIR"
FEL=fel
METHOD=${METHOD:-fel}
AFTER_FLASHING=${AFTER_FLASHING:-boot}
AFTER_FLASHING=${AFTER_FLASHING:-wait}
echo "BUILDROOT_OUTPUT_DIR = $BUILDROOT_OUTPUT_DIR"
NAND_ERASE_BB=false
if [ "$1" == "erase-bb" ]; then
@ -17,7 +41,7 @@ fi
PATH=$PATH:$BUILDROOT_OUTPUT_DIR/host/usr/bin
TMPDIR=`mktemp -d -t chipflashXXXXXX`
PADDED_SPL="$TMPDIR/sunxi-padded-spl"
PADDED_SPL="${BUILDROOT_OUTPUT_DIR}/images/sunxi-spl-with-ecc.bin"
PADDED_SPL_SIZE=0
UBOOT_SCRIPT="$TMPDIR/uboot.scr"
UBOOT_SCRIPT_MEM_ADDR=0x43100000
@ -29,6 +53,7 @@ PADDED_UBOOT="$TMPDIR/padded-uboot"
PADDED_UBOOT_SIZE=0xc0000
UBOOT_MEM_ADDR=0x4a000000
UBI="$BUILDROOT_OUTPUT_DIR/images/rootfs.ubi"
SPARSE_UBI="${TMPDIR}/rootfs.ubi.sparse"
UBI_MEM_ADDR=0x4b000000
UBI_SIZE=`filesize $UBI | xargs printf "0x%08x"`
@ -36,31 +61,22 @@ PAGE_SIZE=16384
OOB_SIZE=1664
prepare_images() {
local in=$SPL
local out=$PADDED_SPL
if [ -e $out ]; then
rm $out
fi
if [[ ! -e "${SCRIPTDIR}/spl-image-builder" ]]; then
pushd "${SCRIPTDIR}"
make
popd
#PADDED_SPL_SIZE in pages
if [[ ! -e "${PADDED_SPL}" ]]; then
echo "ERROR: can not read ${PADDED_SPL}"
exit 1
fi
"${SCRIPTDIR}/spl-image-builder" -d -r 3 -u 4096 -o 1664 -p 16384 -c 1024 -s 64 "$in" "$out"
#PADDED_SPL_SIZE in pages
PADDED_SPL_SIZE=$(filesize "$out")
PADDED_SPL_SIZE=$(filesize "${PADDED_SPL}")
PADDED_SPL_SIZE=$(($PADDED_SPL_SIZE / ($PAGE_SIZE + $OOB_SIZE)))
PADDED_SPL_SIZE=$(echo $PADDED_SPL_SIZE | xargs printf "0x%08x")
echo "filesize= $(filesize "$out")"
echo "PADDED_SPL_SIZE=$PADDED_SPL_SIZE"
# Align the u-boot image on a page boundary
dd if="$UBOOT" of="$PADDED_UBOOT" bs=16k conv=sync
UBOOT_SIZE=`filesize "$PADDED_UBOOT" | xargs printf "0x%08x"`
echo "UBOOT_SIZE=${UBOOT_SIZE}"
echo "PADDED_UBOOT_SIZE=${PADDED_UBOOT_SIZE}"
dd if=/dev/urandom of="$PADDED_UBOOT" seek=$((UBOOT_SIZE / 0x4000)) bs=16k count=$(((PADDED_UBOOT_SIZE - UBOOT_SIZE) / 0x4000))
}
@ -70,25 +86,33 @@ prepare_uboot_script() {
else
echo "nand erase 0x0 0x200000000" > "${UBOOT_SCRIPT_SRC}"
fi
echo "echo sunxi_nand config spl" >> "${UBOOT_SCRIPT_SRC}"
echo "sunxi_nand config spl" >> "${UBOOT_SCRIPT_SRC}"
echo "echo nand write.raw $SPL_MEM_ADDR 0x0 $PADDED_SPL_SIZE" >> "${UBOOT_SCRIPT_SRC}"
echo "nand write.raw $SPL_MEM_ADDR 0x0 $PADDED_SPL_SIZE" >> "${UBOOT_SCRIPT_SRC}"
echo "echo nand write.raw $SPL_MEM_ADDR 0x400000 $PADDED_SPL_SIZE" >> "${UBOOT_SCRIPT_SRC}"
echo "nand write.raw $SPL_MEM_ADDR 0x400000 $PADDED_SPL_SIZE" >> "${UBOOT_SCRIPT_SRC}"
echo "sunxi_nand config default" >> "${UBOOT_SCRIPT_SRC}"
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}"
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}"
echo "setenv bootcmd 'source \${scriptaddr}; nand slc-mode on; 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}"
echo "saveenv" >> "${UBOOT_SCRIPT_SRC}"
echo "setenv bootcmd '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}"
echo "setenv fel_booted 0" >> "${UBOOT_SCRIPT_SRC}"
echo "echo Enabling Splash" >> "${UBOOT_SCRIPT_SRC}"
echo "setenv stdout serial" >> "${UBOOT_SCRIPT_SRC}"
echo "setenv stderr serial" >> "${UBOOT_SCRIPT_SRC}"
echo "setenv splashpos m,m" >> "${UBOOT_SCRIPT_SRC}"
echo "echo Configuring Video Mode"
echo "setenv video-mode sunxi:640x480-24@60,monitor=composite-ntsc,overscan_x=40,overscan_y=20" >> "${UBOOT_SCRIPT_SRC}"
echo "saveenv" >> "${UBOOT_SCRIPT_SRC}"
if [[ "${METHOD}" == "fel" ]]; then
echo "nand slc-mode on" >> "${UBOOT_SCRIPT_SRC}"
echo "nand write.trimffs $UBI_MEM_ADDR 0x1000000 $UBI_SIZE" >> "${UBOOT_SCRIPT_SRC}"
echo "nand write.slc-mode.trimffs $UBI_MEM_ADDR 0x1000000 $UBI_SIZE" >> "${UBOOT_SCRIPT_SRC}"
echo "mw \${scriptaddr} 0x0" >> "${UBOOT_SCRIPT_SRC}"
else
echo "echo going to fastboot mode" >>"${UBOOT_SCRIPT_SRC}"
echo "fastboot" >>"${UBOOT_SCRIPT_SRC}"
echo "fastboot 0" >>"${UBOOT_SCRIPT_SRC}"
fi
if [[ "${AFTER_FLASHING}" == "boot" ]]; then
@ -106,27 +130,17 @@ prepare_uboot_script() {
mkimage -A arm -T script -C none -n "flash CHIP" -d "${UBOOT_SCRIPT_SRC}" "${UBOOT_SCRIPT}"
}
##############################################################
# main
##############################################################
while getopts "fl" opt; do
case $opt in
f)
echo "fastboot enabled"
METHOD=fastboot
;;
l)
echo "factory mode remain in u-boot after flashing"
AFTER_FLASHING=loop
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
assert_error() {
ERR=$?
ERRCODE=$1
if [ "${ERR}" != "0" ]; then
if [ -z "${ERR}" ]; then
exit ${ERR}
else
exit ${ERRCODE}
fi
fi
}
echo == preparing images ==
prepare_images
@ -137,38 +151,50 @@ if ! wait_for_fel; then
echo "ERROR: please make sure CHIP is connected and jumpered in FEL mode"
fi
${FEL} spl "${SPL}"
assert_error 128
sleep 1 # wait for DRAM initialization to complete
echo == upload spl ==
${FEL} write $SPL_MEM_ADDR "${PADDED_SPL}"
${FEL} write $SPL_MEM_ADDR "${PADDED_SPL}" || ( echo "ERROR: could not write ${PADDED_SPL}" && exit $? )
assert_error 129
echo == upload u-boot ==
${FEL} write $UBOOT_MEM_ADDR "${PADDED_UBOOT}"
${FEL} write $UBOOT_MEM_ADDR "${PADDED_UBOOT}" || ( echo "ERROR: could not write ${PADDED_UBOOT}" && exit $? )
assert_error 130
echo == upload u-boot script ==
${FEL} write $UBOOT_SCRIPT_MEM_ADDR "${UBOOT_SCRIPT}"
${FEL} write $UBOOT_SCRIPT_MEM_ADDR "${UBOOT_SCRIPT}" || ( echo "ERROR: could not write ${UBOOT_SCRIPT}" && exit $? )
assert_error 131
if [[ "${METHOD}" == "fel" ]]; then
echo == upload ubi ==
${FEL} --progress write $UBI_MEM_ADDR "${UBI}"
echo == upload ubi ==
${FEL} --progress write $UBI_MEM_ADDR "${UBI}"
echo == execute the main u-boot binary ==
${FEL} exe $UBOOT_MEM_ADDR
echo == execute the main u-boot binary ==
${FEL} exe $UBOOT_MEM_ADDR
echo == write ubi ==
echo == write ubi ==
else
echo == execute the main u-boot binary ==
${FEL} exe $UBOOT_MEM_ADDR
echo == waiting for fastboot ==
if wait_for_fastboot; then
fastboot -S 0 -u flash UBI ${BUILDROOT_OUTPUT_DIR}/images/rootfs.ubi
fastboot continue
else
rm -rf "${TMPDIR}"
exit 1
fi
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
fi
rm -rf "${TMPDIR}"

@ -0,0 +1,279 @@
#!/bin/bash
SCRIPTDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source $SCRIPTDIR/common.sh
RUN_ALL_STAGES=true
NUM_STAGES=5
stage=()
for i in $(seq 0 $NUM_STAGES); do
stage+=(false)
done
##############################################################
# main
##############################################################
TEMP=`getopt -o "sflu:n:" --long "fel,fastboot,loop-after-flash,stage:,chip-path:" -- "$@"`
eval set -- "$TEMP"
while true; do
case $1 in
-s|--fel)
echo "fel method enabled"
METHOD=fel
shift
;;
-f|--fastboot)
echo "fastboot method enabled"
METHOD=fastboot
shift
;;
-l|--loop-after-flash)
echo "factory mode remain in u-boot after flashing"
AFTER_FLASHING=loop
shift
;;
-u)
BUILDROOT_OUTPUT_DIR="${2}"
shift
shift
;;
--stage)
if [ "${2}" -ge 0 -a "${2}" -le $NUM_STAGES ]; then
echo "Enabling stage ${2}"
stage[${2}]=true
RUN_ALL_STAGES=false
else
echo "Unknown stage: ${2}"
fi
shift
shift
;;
-n|--chip-path)
CHIP_PATH=$2
FEL_DEVICE="--dev $(udevadm info ${CHIP_PATH} | grep "E\: BUSNUM" | awk -F "=" '{ print $NF }'| sed 's/^0*//'):$(udevadm info ${CHIP_PATH} | grep "E\: DEVNUM" | awk -F "=" '{ print $NF }'| sed 's/^0*//')"
FASTBOOT_PORT="-s usb:$(udevadm info ${CHIP_PATH} | grep "P\:" | awk -F "/" '{print $NF}')"
echo "Fastboot port: ${FASTBOOT_PORT}"
echo "FEL device: ${FEL_DEVICE}"
shift
shift
;;
--)
shift; break;;
*)
echo "Invalid option: -$1" >&2
exit 1
break
;;
esac
done
log() {
echo " ${FEL_DEVICE}: $@"
}
BUILDROOT_OUTPUT_DIR="${BUILDROOT_OUTPUT_DIR:-$(pwd)/.firmware}"
log "BUILDROOT_OUTPUT_DIR = $BUILDROOT_OUTPUT_DIR"
if ${RUN_ALL_STAGES}; then
log "Running all stages"
for i in $(seq 0 $NUM_STAGES); do
stage[i]=true
done
fi
FEL="fel ${FEL_DEVICE}"
METHOD=${METHOD:-fastboot}
AFTER_FLASHING=${AFTER_FLASHING:-wait}
NAND_ERASE_BB=false
if [ "$1" == "erase-bb" ]; then
NAND_ERASE_BB=true
fi
PATH=$PATH:$BUILDROOT_OUTPUT_DIR/host/usr/bin
TMPDIR="${BUILDROOT_OUTPUT_DIR}/tmp"
PADDED_SPL="${BUILDROOT_OUTPUT_DIR}/images/sunxi-spl-with-ecc.bin"
PADDED_SPL_SIZE=0
UBOOT_SCRIPT="$TMPDIR/uboot.scr"
UBOOT_SCRIPT_MEM_ADDR=0x43100000
UBOOT_SCRIPT_SRC="$TMPDIR/uboot.cmds"
SPL="$BUILDROOT_OUTPUT_DIR/images/sunxi-spl.bin"
SPL_MEM_ADDR=0x43000000
UBOOT="$BUILDROOT_OUTPUT_DIR/images/u-boot-dtb.bin"
PADDED_UBOOT="$TMPDIR/padded-uboot"
PADDED_UBOOT_SIZE=0xc0000
UBOOT_MEM_ADDR=0x4a000000
UBI="$BUILDROOT_OUTPUT_DIR/images/rootfs.ubi"
SPARSE_UBI="${TMPDIR}/rootfs.ubi.sparse"
UBI_MEM_ADDR=0x4b000000
log "Temporary directory: ${TMPDIR}"
if [ ! -d "${TMPDIR}" ]; then
log "Making directory: ${TMPDIR}"
mkdir -p "${TMPDIR}"
fi
UBI_SIZE=`filesize $UBI | xargs printf "0x%08x"`
PAGE_SIZE=16384
OOB_SIZE=1664
prepare_images() {
#PADDED_SPL_SIZE in pages
if [[ ! -e "${PADDED_SPL}" ]]; then
log "ERROR: can not read ${PADDED_SPL}"
exit 1
fi
PADDED_SPL_SIZE=$(filesize "${PADDED_SPL}")
PADDED_SPL_SIZE=$(($PADDED_SPL_SIZE / ($PAGE_SIZE + $OOB_SIZE)))
PADDED_SPL_SIZE=$(echo $PADDED_SPL_SIZE | xargs printf "0x%08x")
log "PADDED_SPL_SIZE=$PADDED_SPL_SIZE"
# Align the u-boot image on a page boundary
dd if="$UBOOT" of="$PADDED_UBOOT" bs=16k conv=sync
UBOOT_SIZE=`filesize "$PADDED_UBOOT" | xargs printf "0x%08x"`
log "UBOOT_SIZE=${UBOOT_SIZE}"
log "PADDED_UBOOT_SIZE=${PADDED_UBOOT_SIZE}"
dd if=/dev/urandom of="$PADDED_UBOOT" seek=$((UBOOT_SIZE / 0x4000)) bs=16k count=$(((PADDED_UBOOT_SIZE - UBOOT_SIZE) / 0x4000))
}
prepare_uboot_script() {
if [ "$NAND_ERASE_BB" = true ] ; then
echo "nand scrub -y 0x0 0x200000000" > "${UBOOT_SCRIPT_SRC}"
else
echo "nand erase 0x0 0x200000000" > "${UBOOT_SCRIPT_SRC}"
fi
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}"
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}"
echo "setenv bootcmd '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}"
echo "setenv fel_booted 0" >> "${UBOOT_SCRIPT_SRC}"
echo "echo Enabling Splash" >> "${UBOOT_SCRIPT_SRC}"
echo "setenv stdout serial" >> "${UBOOT_SCRIPT_SRC}"
echo "setenv stderr serial" >> "${UBOOT_SCRIPT_SRC}"
echo "setenv splashpos m,m" >> "${UBOOT_SCRIPT_SRC}"
echo "echo Configuring Video Mode"
echo "setenv video-mode sunxi:640x480-24@60,monitor=composite-ntsc,overscan_x=40,overscan_y=20" >> "${UBOOT_SCRIPT_SRC}"
echo "saveenv" >> "${UBOOT_SCRIPT_SRC}"
if [[ "${METHOD}" == "fel" ]]; then
echo "nand write.slc-mode.trimffs $UBI_MEM_ADDR 0x1000000 $UBI_SIZE" >> "${UBOOT_SCRIPT_SRC}"
echo "mw \${scriptaddr} 0x0" >> "${UBOOT_SCRIPT_SRC}"
else
echo "echo going to fastboot mode" >>"${UBOOT_SCRIPT_SRC}"
echo "fastboot 0" >>"${UBOOT_SCRIPT_SRC}"
fi
if [[ "${AFTER_FLASHING}" == "boot" ]]; then
echo "echo " >>"${UBOOT_SCRIPT_SRC}"
echo "echo *****************[ BOOT ]*****************" >>"${UBOOT_SCRIPT_SRC}"
echo "echo " >>"${UBOOT_SCRIPT_SRC}"
echo "boot" >> "${UBOOT_SCRIPT_SRC}"
else
echo "echo " >>"${UBOOT_SCRIPT_SRC}"
echo "echo *****************[ FLASHING DONE ]*****************" >>"${UBOOT_SCRIPT_SRC}"
echo "echo " >>"${UBOOT_SCRIPT_SRC}"
echo "while true; do; sleep 10; done;" >>"${UBOOT_SCRIPT_SRC}"
fi
mkimage -A arm -T script -C none -n "flash CHIP" -d "${UBOOT_SCRIPT_SRC}" "${UBOOT_SCRIPT}"
}
assert_error() {
ERR=$?
ERRCODE=$1
if [ "${ERR}" != "0" ]; then
if [ -z "${ERR}" ]; then
exit ${ERR}
else
exit ${ERRCODE}
fi
fi
}
if ${stage[0]}; then
log "== preparing images =="
if [ ! -f "${PADDED_UBOOT}" ]; then
prepare_images > /dev/null
fi
if [ ! -f "${UBOOT_SCRIPT}" ]; then
prepare_uboot_script > /dev/null
fi
log "== upload the SPL to SRAM and execute it =="
${FEL} spl "${SPL}" > /dev/null
assert_error 128
sleep 1 # wait for DRAM initialization to complete
fi
if ${stage[1]}; then
log "== upload spl =="
${FEL} write $SPL_MEM_ADDR "${PADDED_SPL}" > /dev/null
assert_error 129
fi
if ${stage[2]}; then
log "== upload u-boot =="
${FEL} write $UBOOT_MEM_ADDR "${PADDED_UBOOT}" > /dev/null
assert_error 130
fi
if ${stage[3]}; then
log "== upload u-boot script =="
${FEL} write $UBOOT_SCRIPT_MEM_ADDR "${UBOOT_SCRIPT}" || ( echo "ERROR: could not write ${UBOOT_SCRIPT}" && exit $? )
assert_error 131
fi
if [[ "${METHOD}" == "fel" ]]; then
if ${stage[4]}; then
log "== upload ubi =="
${FEL} write $UBI_MEM_ADDR "${UBI}" > /dev/null
assert_error 132
fi
if ${stage[5]}; then
log "== execute the main u-boot binary =="
${FEL} exe $UBOOT_MEM_ADDR > /dev/null
assert_error 133
fi
# rm -rf "${TMPDIR}"
else
if ${stage[4]}; then
log "== execute the main u-boot binary =="
${FEL} exe $UBOOT_MEM_ADDR > /dev/null
assert_error 132
fi
if ${stage[5]}; then
log "== creating sparse image =="
if [ ! -f "${SPARSE_UBI}" ]; then
img2simg ${UBI} ${SPARSE_UBI} $((2*1024*1024)) &> /dev/null
fi
assert_error 133
log "== waiting for fastboot =="
if wait_for_fastboot ${FASTBOOT_PORT}; then
fastboot ${FASTBOOT_PORT} -i 0x1f3a -u flash UBI ${SPARSE_UBI} > /dev/null
assert_error 134
fastboot ${FASTBOOT_PORT} -i 0x1f3a continue > /dev/null
assert_error 135
else
exit 1
fi
# rm -rf "${TMPDIR}"
fi
fi

@ -3,9 +3,15 @@
SCRIPTDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source $SCRIPTDIR/common.sh
if ! wait_for_fel; then
echo "ERROR: please jumper your CHIP in FEL mode then power on"
exit 1
fi
FLASH_SCRIPT=./chip-fel-flash.sh
WHAT=buildroot
BRANCH=stable
BRANCH=next
function require_directory {
if [[ ! -d "${1}" ]]; then
@ -32,17 +38,23 @@ function cache_download {
if [[ "${S3_MD5}" != "${MD5}" ]]; then
echo "md5sum differs"
rm ${DEST_DIR}/${FILE}
wget -P "${FW_IMAGE_DIR}" "${SRC_URL}/${FILE}"
if ! wget -P "${FW_IMAGE_DIR}" "${SRC_URL}/${FILE}"; then
echo "download of ${SRC_URL}/${FILE} failed!"
exit $?
fi
else
echo "file already downloaded"
fi
else
wget -P "${FW_IMAGE_DIR}" "${SRC_URL}/${FILE}"
if ! wget -P "${FW_IMAGE_DIR}" "${SRC_URL}/${FILE}"; then
echo "download of ${SRC_URL}/${FILE} failed!"
exit $?
fi
fi
}
while getopts "ufd" opt; do
while getopts "ufdb:w:B:" opt; do
case $opt in
u)
echo "updating cache"
@ -54,6 +66,18 @@ while getopts "ufd" opt; do
echo "fastboot enabled"
FLASH_SCRIPT_OPTION="-f"
;;
B)
BUILD="$OPTARG"
echo "BUILD = ${BUILD}"
;;
b)
BRANCH="$OPTARG"
echo "BRANCH = ${BRANCH}"
;;
w)
WHAT="$OPTARG"
echo "WHAT = ${WHAT}"
;;
d)
echo "debian selected"
WHAT="debian"
@ -71,10 +95,14 @@ FW_IMAGE_DIR="${FW_DIR}/images"
BASE_URL="http://opensource.nextthing.co/chip"
S3_URL="${BASE_URL}/${WHAT}/${BRANCH}/latest"
ROOTFS_URL="$(wget -q -O- ${S3_URL})" || (echo "ERROR: cannot reach ${S3_URL}" && exit 1)
if [[ -z "${ROOTFS_URL}" ]]; then
echo "error: could not get URL for latest build from ${S3_URL} - check internet connection"
exit 1
if [[ -z "$BUILD" ]]; then
ROOTFS_URL="$(wget -q -O- ${S3_URL})" || (echo "ERROR: cannot reach ${S3_URL}" && exit 1)
if [[ -z "${ROOTFS_URL}" ]]; then
echo "error: could not get URL for latest build from ${S3_URL} - check internet connection"
exit 1
fi
else
ROOTFS_URL="${S3_URL%latest}$BUILD"
fi
if [[ "${WHAT}" == "buildroot" ]]; then
@ -84,7 +112,7 @@ if [[ "${WHAT}" == "buildroot" ]]; then
BR_URL="${ROOTFS_URL}"
else
BR_BUILD="$(wget -q -O- ${ROOTFS_URL}/br_build)"
BR_URL="${BASE_URL}/buildroot/${BRANCH}/${BR_BUILD}/images"
BR_URL="${BASE_URL}/buildroot/${BRANCH%-gui}/${BR_BUILD}/images"
BUILD="$(wget -q -O- ${ROOTFS_URL}/build)"
fi
@ -97,15 +125,15 @@ require_directory "${FW_IMAGE_DIR}"
cache_download "${FW_IMAGE_DIR}" ${ROOTFS_URL} rootfs.ubi
cache_download "${FW_IMAGE_DIR}" ${BR_URL} sun5i-r8-chip.dtb
cache_download "${FW_IMAGE_DIR}" ${BR_URL} sunxi-spl.bin
cache_download "${FW_IMAGE_DIR}" ${BR_URL} sunxi-spl-with-ecc.bin
cache_download "${FW_IMAGE_DIR}" ${BR_URL} uboot-env.bin
cache_download "${FW_IMAGE_DIR}" ${BR_URL} zImage
cache_download "${FW_IMAGE_DIR}" ${BR_URL} u-boot-dtb.bin
BUILDROOT_OUTPUT_DIR="${FW_DIR}" ${FLASH_SCRIPT} ${FLASH_SCRIPT_OPTION}
BUILDROOT_OUTPUT_DIR="${FW_DIR}" ${FLASH_SCRIPT} ${FLASH_SCRIPT_OPTION} || echo "ERROR: could not flash" && exit 1
if ! wait_for_linuxboot; then
echo "ERROR: could not flash"
rm -rf ${TMPDIR}
exit 1
else
${SCRIPTDIR}/verify.sh

@ -1,6 +1,7 @@
#!/bin/bash
TIMEOUT=30
FEL=fel
#------------------------------------------------------------
onMac() {
@ -24,7 +25,7 @@ filesize() {
wait_for_fastboot() {
echo -n "waiting for fastboot...";
for ((i=$TIMEOUT; i>0; i--)) {
if [[ ! -z "$(fastboot devices)" ]]; then
if [[ ! -z "$(fastboot -i 0x1f3a $@ devices)" ]]; then
echo "OK";
return 0;
fi
@ -40,7 +41,7 @@ wait_for_fastboot() {
wait_for_fel() {
echo -n "waiting for fel...";
for ((i=$TIMEOUT; i>0; i--)) {
if ${FEL} ver 2>/dev/null >/dev/null; then
if ${FEL} $@ ver 2>/dev/null >/dev/null; then
echo "OK"
return 0;
fi

Loading…
Cancel
Save