Browse Source

Initial commit

chip/stable
computermouth 6 years ago
parent
commit
fd388104fb
  1. 144
      chip-TOSH4GB-flash.sh
  2. 137
      chip-create-nand-images.sh
  3. 11
      chip-flash-nand-images.sh
  4. 204
      chip-local-flash.sh
  5. 211
      chip-update-firmware.sh
  6. 119
      common.sh

144
chip-TOSH4GB-flash.sh

@ -1,144 +0,0 @@
#!/bin/bash
set -x
SCRIPTDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source $SCRIPTDIR/common.sh
##############################################################
# main
##############################################################
while getopts "flpu:" 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}"
;;
p)
POCKET_CHIP=true
;;
\?)
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:-wait}
NAND_ERASE_BB=false
if [ "$1" == "erase-bb" ]; then
NAND_ERASE_BB=true
fi
PATH=$PATH:$BUILDROOT_OUTPUT_DIR/host/usr/bin
TMPDIR=`mktemp -d -t chipflashXXXXXX`
PADDED_SPL="${BUILDROOT_OUTPUT_DIR}/images/sunxi-spl-with-ecc.bin"
PADDED_SPL_SIZE=0
UBOOT_SCRIPT="${BUILDROOT_OUTPUT_DIR}/images/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="$BUILDROOT_OUTPUT_DIR/images/padded-u-boot"
PADDED_UBOOT_SIZE=0x400000
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"`
PAGE_SIZE=16384
OOB_SIZE=1280
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
#prepare_uboot_script
echo == upload the SPL to SRAM and execute it ==
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}" || ( echo "ERROR: could not write ${PADDED_SPL}" && exit $? )
assert_error 129
echo == upload u-boot ==
${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}" || ( 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 == execute the main u-boot binary ==
${FEL} exe $UBOOT_MEM_ADDR
echo == write ubi ==
else
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 $UBI
assert_error 134
fastboot -i 0x1f3a continue
assert_error 135
else
rm -rf "${TMPDIR}"
exit 1
fi
fi
if [[ "${METHOD}" == "fel" ]]; then
if ! wait_for_linuxboot; then
echo "ERROR: could not flash":
rm -rf ${TMPDIR}
exit 1
else
${SCRIPTDIR}/verify.sh
fi
fi
rm -rf "${TMPDIR}"

137
chip-create-nand-images.sh

@ -0,0 +1,137 @@
#!/bin/bash
FEL=sunxi-fel
SCRIPTDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source $SCRIPTDIR/common.sh
UBOOTDIR="$1"
ROOTFSTAR="$2"
OUTPUTDIR="$3"
# build the UBI image
prepare_ubi() {
local tmpdir=`mktemp -d -t chip-ubi-XXXXXX`
local rootfs=$tmpdir/rootfs
local ubifs=$tmpdir/rootfs.ubifs
local ubicfg=$tmpdir/ubi.cfg
local outputdir="$1"
local rootfstar="$2"
local nandtype="$3"
local maxlebcount="$4"
local eraseblocksize="$5"
local pagesize="$6"
local subpagesize="$7"
local ebsize=`printf %x $eraseblocksize`
local psize=`printf %x $pagesize`
local ubi=$outputdir/chip-$ebsize-$psize.ubi
local sparseubi=$outputdir/chip-$ebsize-$psize.ubi.sparse
local mlcopts=""
if [ -z $subpagesize ]; then
subpagesize=$pagesize
fi
if [ "$nandtype" = "mlc" ]; then
lebsize=$((eraseblocksize/2-$pagesize*2))
mlcopts="-M dist3"
elif [ $subpagesize -lt $pagesize ]; then
lebsize=$((eraseblocksize-pagesize))
else
lebsize=$((eraseblocksize-pagesize*2))
fi
mkdir -p $rootfs
tar -xf $rootfstar -C $rootfs
mkfs.ubifs -d $rootfs -m $pagesize -e $lebsize -c $maxlebcount -o $ubifs
echo "[rootfs]
mode=ubi
vol_id=0
vol_type=dynamic
vol_name=rootfs
vol_alignment=1
vol_flags=autoresize
image=$ubifs" > $ubicfg
ubinize -o $ubi -p $eraseblocksize -m $pagesize -s $subpagesize $mlcopts $ubicfg
img2simg $ubi $sparseubi $eraseblocksize
rm -rf $tmpdir
}
# build the SPL image
prepare_spl() {
local tmpdir=`mktemp -d -t chip-spl-XXXXXX`
local outputdir=$1
local spl=$2
local eraseblocksize=$3
local pagesize=$4
local oobsize=$5
local repeat=$((eraseblocksize/pagesize/64))
local nandspl=$tmpdir/nand-spl.bin
local nandpaddedspl=$tmpdir/nand-padded-spl.bin
local ebsize=`printf %x $eraseblocksize`
local psize=`printf %x $pagesize`
local osize=`printf %x $oobsize`
local nandrepeatedspl=$outputdir/spl-$ebsize-$psize-$osize.bin
local padding=$tmpdir/padding
local splpadding=$tmpdir/nand-spl-padding
sunxi-nand-image-builder -c 64/1024 -p $pagesize -o $oobsize -u 1024 -e $eraseblocksize -b -s $spl $nandspl
local splsize=`filesize $nandspl`
local paddingsize=$((64-(splsize/(pagesize+oobsize))))
local i=0
while [ $i -lt $repeat ]; do
dd if=/dev/urandom of=$padding bs=1024 count=$paddingsize
sunxi-nand-image-builder -c 64/1024 -p $pagesize -o $oobsize -u 1024 -e $eraseblocksize -b -s $padding $splpadding
cat $nandspl $splpadding > $nandpaddedspl
if [ "$i" -eq "0" ]; then
cat $nandpaddedspl > $nandrepeatedspl
else
cat $nandpaddedspl >> $nandrepeatedspl
fi
i=$((i+1))
done
rm -rf $tmpdir
}
# build the bootloader image
prepare_uboot() {
local outputdir=$1
local uboot=$2
local eraseblocksize=$3
local ebsize=`printf %x $eraseblocksize`
local paddeduboot=$outputdir/uboot-$ebsize.bin
dd if=$uboot of=$paddeduboot bs=$eraseblocksize conv=sync
}
## copy the source images in the output dir ##
mkdir -p $OUTPUTDIR
cp $UBOOTDIR/spl/sunxi-spl.bin $OUTPUTDIR/
cp $UBOOTDIR/u-boot-dtb.bin $OUTPUTDIR/
cp $ROOTFSTAR $OUTPUTDIR/
## prepare ubi images ##
# Toshiba SLC image:
prepare_ubi $OUTPUTDIR $ROOTFSTAR "slc" 2048 262144 4096 1024
# Toshiba/Hynix MLC image:
prepare_ubi $OUTPUTDIR $ROOTFSTAR "mlc" 4096 4194304 16384 16384
## prepare spl images ##
# Toshiba SLC image:
prepare_spl $OUTPUTDIR $UBOOTDIR/spl/sunxi-spl.bin 262144 4096 256
# Toshiba MLC image:
prepare_spl $OUTPUTDIR $UBOOTDIR/spl/sunxi-spl.bin 4194304 16384 1280
# Hynix MLC image:
prepare_spl $OUTPUTDIR $UBOOTDIR/spl/sunxi-spl.bin 4194304 16384 1664
## prepare uboot images ##
# Toshiba SLC image:
prepare_uboot $OUTPUTDIR $UBOOTDIR/u-boot-dtb.bin 262144
# Toshiba/Hynix MLC image:
prepare_uboot $OUTPUTDIR $UBOOTDIR/u-boot-dtb.bin 4194304

11
chip-flash-nand-images.sh

@ -0,0 +1,11 @@
#!/bin/bash
SCRIPTDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source $SCRIPTDIR/common.sh
IMAGESDIR="$1"
ERASEMODE="$2"
PLATFORM="$3"
detect_nand
flash_images

204
chip-local-flash.sh

@ -1,204 +0,0 @@
#!/bin/bash
set -x
SCRIPTDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source $SCRIPTDIR/common.sh
BUILDROOT_OUTPUT_DIR=".new/firmware"
FIRMWARE_DIR=".new/firmware"
DL_METHOD=fel
METHOD=fel
DL_FLAVOR=serv
DL_DIST=rootfs
DL_DIR=".dl"
while getopts "fdphnu:" opt; do
case $opt in
f)
echo "fastboot enabled"
DL_METHOD=fb
METHOD=fastboot
;;
d)
echo "desktop selected"
DL_FLAVOR=desk
;;
p)
echo "desktop selected"
DL_FLAVOR=pocket
;;
h)
echo "desktop selected"
DL_FLAVOR=hdmi-fixture-rootfs
;;
n)
echo "next enabled"
DL_DIST=testing-rootfs
;;
u)
BUILDROOT_OUTPUT_DIR="${OPTARG}"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
if [[ "${DL_FLAVOR}" == "pocket" ]] && [[ "${DL_DIST}" == "testing-rootfs" ]]; then
DL_FLAVOR="pocket-next"
fi
echo "BUILDROOT_OUTPUT_DIR = $BUILDROOT_OUTPUT_DIR"
function require_directory {
if [[ ! -d "${1}" ]]; then
mkdir -p "${1}"
fi
}
function dl_check {
wget -O $DL_DIR/latest.md5\
opensource.nextthing.co/chippian/$DL_DIST/latest.md5
pushd $DL_DIR
if [[ $(cat latest.md5 | grep "`md5sum img-$DL_FLAVOR-$DL_METHOD.tar.gz`")\
&& -d "img-$DL_FLAVOR-$DL_METHOD/images" ]]; then
echo "Cached files located"
echo "Staging for flashing"
cp -R img-$DL_FLAVOR-$DL_METHOD/images ../$FIRMWARE_DIR/
else
echo "New image available"
rm -rf img-$DL_FLAVOR-$DL_METHOD*
if [[ "${DL_FLAVOR}" == "pocket" || "${DL_FLAVOR}" == "pocket-next" ]]; then
wget opensource.nextthing.co/chippian/rootfs/img-$DL_FLAVOR-$DL_METHOD.tar.gz|| exit 1
else
wget opensource.nextthing.co/chippian/$DL_DIST/img-$DL_FLAVOR-$DL_METHOD.tar.gz|| exit 1
fi
echo "Extracting.."
tar -xf img-$DL_FLAVOR-$DL_METHOD.tar.gz
echo "Staging for flashing"
cp -R img-$DL_FLAVOR-$DL_METHOD/images ../$FIRMWARE_DIR/
fi
popd
}
require_directory "$FIRMWARE_DIR"
require_directory "$DL_DIR"
dl_check
FEL=fel
METHOD=${METHOD:-fel}
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=`mktemp -d -t chipflashXXXXXX`
PADDED_SPL="${BUILDROOT_OUTPUT_DIR}/images/sunxi-spl-with-ecc.bin"
PADDED_SPL_SIZE=0
UBOOT_SCRIPT="${BUILDROOT_OUTPUT_DIR}/images/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="$BUILDROOT_OUTPUT_DIR/images/padded-u-boot"
PADDED_UBOOT_SIZE=0x400000
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"`
PAGE_SIZE=16384
OOB_SIZE=1280
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
#prepare_uboot_script
echo == upload the SPL to SRAM and execute it ==
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}" || ( echo "ERROR: could not write ${PADDED_SPL}" && exit $? )
assert_error 129
echo == upload u-boot ==
${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}" || ( 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 == execute the main u-boot binary ==
${FEL} exe $UBOOT_MEM_ADDR
echo == write ubi ==
else
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 $UBI
assert_error 134
fastboot -i 0x1f3a continue
assert_error 135
else
rm -rf "${TMPDIR}"
exit 1
fi
fi
if [[ "${METHOD}" == "fel" ]]; then
if ! wait_for_linuxboot; then
echo "ERROR: could not flash":
rm -rf ${TMPDIR}
exit 1
else
${SCRIPTDIR}/verify.sh
fi
fi
rm -rf "${TMPDIR}"

211
chip-update-firmware.sh

@ -3,46 +3,60 @@
SCRIPTDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source $SCRIPTDIR/common.sh
BUILDROOT_OUTPUT_DIR=".new/firmware"
FIRMWARE_DIR=".new/firmware"
DL_DIR=".dl"
IMAGESDIR=".new/firmware/images"
DL_URL="http://opensource.nextthing.co/chip/images"
METHOD=fel
FLAVOR=buildroot
FLAVOR=server
BRANCH=stable
DL_DIR=".dl"
NO_LIM="lim"
while getopts "fsdpb:l:" opt; do
PROBES=(spl-40000-1000-100.bin
spl-400000-4000-500.bin
spl-400000-4000-680.bin
sunxi-spl.bin
u-boot-dtb.bin
uboot-40000.bin
uboot-400000.bin)
UBI_PREFIX="chip"
UBI_SUFFIX="ubi.sparse"
UBI_TYPE="400000-4000"
while getopts "sgpbhB:" opt; do
case $opt in
f)
echo "fastboot enabled"
METHOD=fb
;;
s)
echo "server selected"
FLAVOR=serv
FLAVOR=server
;;
d)
echo "desktop selected"
METHOD=fb ##must fastboot
FLAVOR=desk
g)
echo "gui selected"
FLAVOR=gui
;;
p)
echo "pocketchip selected"
METHOD=fb ##must fastboot
FLAVOR=pocket
FLAVOR=pocketchip
;;
b)
echo "buildroot selected"
FLAVOR=buildroot
;;
B)
BRANCH="$OPTARG"
echo "${BRANCH} branch selected"
;;
l)
LOC=1
BUILDROOT_OUTPUT_DIR="$OPTARG"
FIRMWARE_DIR="$OPTARG"
echo "${BUILDROOT_OUTPUT_DIR} directory selected"
h)
echo ""
echo "Help"
echo ""
echo " -s -- Server [Debian + Headless]"
echo " -g -- GUI [Debian + XFCE]"
echo " -p -- PocketCHIP"
echo " -b -- Buildroot"
echo " -B -- Branch(optional) [eg. -B testing]"
echo ""
echo ""
exit 0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
@ -57,136 +71,55 @@ function require_directory {
fi
}
function dl_check {
function dl_probe {
CACHENUM=$(curl $DL_URL/$BRANCH/$FLAVOR/latest)
if [[ ! -f "$DL_DIR/$BRANCH-$FLAVOR-$METHOD-b${CACHENUM}.tar.gz" ]]; then
if [[ ! -d "$DL_DIR/$BRANCH-$FLAVOR-b${CACHENUM}" ]]; then
echo "New image available"
rm -rf $BRANCH-$FLAVOR-$METHOD*
rm -rf $DL_DIR/$BRANCH-$FLAVOR*
mkdir -p $DL_DIR/${BRANCH}-${FLAVOR}-b${CACHENUM}
pushd $DL_DIR/${BRANCH}-${FLAVOR}-b${CACHENUM}
echo "Downloading.."
pushd $DL_DIR
if ! wget -O $BRANCH-$FLAVOR-$METHOD-b${CACHENUM}.tar.gz\
$DL_URL/$BRANCH/$FLAVOR/${CACHENUM}/img-$FLAVOR-$METHOD.tar.gz; then
for FILE in ${PROBES[@]}; do
if ! wget $DL_URL/$BRANCH/$FLAVOR/${CACHENUM}/$FILE; then
echo "download of $BRANCH-$FLAVOR-$METHOD-b${CACHENUM} failed!"
exit $?
fi
done
popd
else
echo "Cached probe files located"
fi
echo "Staging for NAND probe"
ln -s ../../$DL_DIR/${BRANCH}-${FLAVOR}-b${CACHENUM}/ $IMAGESDIR
rm ${IMAGESDIR}/ubi_type
detect_nand
if [[ ! -f "$DL_DIR/$BRANCH-$FLAVOR-b${CACHENUM}/$UBI_PREFIX-$UBI_TYPE.$UBI_SUFFIX" ]]; then
echo "Downloading new UBI, this will be cached for future flashes."
pushd $DL_DIR/${BRANCH}-${FLAVOR}-b${CACHENUM}
if ! wget $DL_URL/$BRANCH/$FLAVOR/${CACHENUM}/$UBI_PREFIX-$UBI_TYPE.$UBI_SUFFIX; then
echo "download of $BRANCH-$FLAVOR-$METHOD-b${CACHENUM} failed!"
exit $?
fi
echo "Extracting.."
tar -xf $BRANCH-$FLAVOR-$METHOD-b${CACHENUM}.tar.gz
mv img-* $BRANCH-$FLAVOR-$METHOD-b${CACHENUM}
echo "Staging for flashing"
cp -R $BRANCH-$FLAVOR-$METHOD-b${CACHENUM}/images ../$FIRMWARE_DIR/
popd
else
pushd $DL_DIR
echo "Cached files located"
echo "Staging for flashing"
cp -R $BRANCH-$FLAVOR-$METHOD-b${CACHENUM}/images ../$FIRMWARE_DIR/
popd
echo "Cached UBI located"
fi
}
FEL=fel
echo == preparing images ==
require_directory "$IMAGESDIR"
rm -rf ${IMAGESDIR}
require_directory "$DL_DIR"
dl_probe
METHOD=${METHOD:-fel}
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
PADDED_SPL="${BUILDROOT_OUTPUT_DIR}/images/sunxi-spl-with-ecc.bin"
PADDED_SPL_SIZE=0
UBOOT_SCRIPT="${BUILDROOT_OUTPUT_DIR}/images/uboot.scr"
UBOOT_SCRIPT_MEM_ADDR=0x43100000
SPL="$BUILDROOT_OUTPUT_DIR/images/sunxi-spl.bin"
SPL_MEM_ADDR=0x43000000
UBOOT="$BUILDROOT_OUTPUT_DIR/images/u-boot-dtb.bin"
PADDED_UBOOT="$BUILDROOT_OUTPUT_DIR/images/padded-u-boot"
UBOOT_MEM_ADDR=0x4a000000
UBI="$BUILDROOT_OUTPUT_DIR/images/rootfs.ubi"
UBI_MEM_ADDR=0x4b000000
assert_error() {
ERR=$?
ERRCODE=$1
if [ "${ERR}" != "0" ]; then
if [ -z "${ERR}" ]; then
exit ${ERR}
else
exit ${ERRCODE}
fi
fi
}
if [[ -z $LOC ]]; then
echo == preparing images ==
require_directory "$FIRMWARE_DIR"
require_directory "$DL_DIR"
dl_check
fi
echo == upload the SPL to SRAM and execute it ==
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}" || ( echo "ERROR: could not write ${PADDED_SPL}" && exit $? )
assert_error 129
echo == upload u-boot ==
${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}" || ( 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 == execute the main u-boot binary ==
${FEL} exe $UBOOT_MEM_ADDR
echo == write ubi ==
else
echo == execute the main u-boot binary ==
${FEL} exe $UBOOT_MEM_ADDR
assert_error 132
echo == waiting for fastboot ==
if wait_for_fastboot; then
fastboot -i 0x1f3a -u flash UBI $UBI
assert_error 134
fastboot -i 0x1f3a continue
assert_error 135
else
exit 1
fi
fi
if [[ "${METHOD}" == "fel" ]]; then
if ! wait_for_linuxboot; then
echo "ERROR: could not flash":
exit 1
else
${SCRIPTDIR}/verify.sh
fi
fi
flash_images
rm ${IMAGESDIR}/ubi_type
ready_to_roll

119
common.sh

@ -1,7 +1,21 @@
#!/bin/bash
TIMEOUT=30
FEL=fel
FEL=sunxi-fel
SPLMEMADDR=0x43000000
UBOOTMEMADDR=0x4a000000
UBOOTSCRMEMADDR=0x43100000
nand_erasesize=400000
nand_writesize=4000
nand_oobsize=680
if [[ -z $(which $FEL) ]]; then
echo " Error: Unable to locate FEL utility."
echo " Install FEL with:"
echo " CHIP-SDK setup script [github.com/NextThingCo/CHIP-SDK]"
echo " - or build from source [github.com/NextThingCo/sunxi-tools]"
exit 1
fi
#------------------------------------------------------------
onMac() {
@ -53,6 +67,107 @@ wait_for_fel() {
return 1
}
detect_nand() {
local tmpdir=`mktemp -d -t chip-uboot-script-XXXXXX`
local ubootcmds=$tmpdir/uboot.cmds
local ubootscr=$tmpdir/uboot.scr
echo "nand info
env export -t -s 0x100 0x7c00 nand_erasesize nand_writesize nand_oobsize
reset" > $ubootcmds
mkimage -A arm -T script -C none -n "detect NAND" -d $ubootcmds $ubootscr
if ! wait_for_fel; then
echo "ERROR: please make sure CHIP is connected and jumpered in FEL mode"
fi
$FEL spl $IMAGESDIR/sunxi-spl.bin
# wait for DRAM initialization to complete
sleep 1
$FEL write $UBOOTMEMADDR $IMAGESDIR/u-boot-dtb.bin
$FEL write $UBOOTSCRMEMADDR $ubootscr
$FEL exe $UBOOTMEMADDR
if ! wait_for_fel; then
echo "ERROR: please make sure CHIP is connected and jumpered in FEL mode"
fi
$FEL read 0x7c00 0x100 $tmpdir/nand-info
echo "NAND detected:"
cat $tmpdir/nand-info
UBI_TYPE="$(cat $tmpdir/nand-info | awk -F= '/erase/ {print $2}')-$(cat $tmpdir/nand-info | awk -F= '/write/ {print $2}')"
echo "${UBI_TYPE}" > $IMAGESDIR/ubi_type
source $tmpdir/nand-info
rm -rf $tmpdir
}
flash_images() {
local tmpdir=`mktemp -d -t chip-uboot-script-XXXXXX`
local ubootcmds=$tmpdir/uboot.cmds
local ubootscr=$tmpdir/uboot.scr
local ubootsize=`filesize $IMAGESDIR/uboot-$nand_erasesize.bin | xargs printf "0x%08x"`
local pagespereb=`echo $((nand_erasesize/nand_writesize)) | xargs printf "%x"`
local sparseubi=$tmpdir/ubi.sparse
if [ "x$ERASEMODE" = "xscrub" ]; then
echo "nand scrub.chip -y" > $ubootcmds
else
echo "nand erase.chip" > $ubootcmds
fi
echo "nand write.raw.noverify $SPLMEMADDR 0x0 $pagespereb" >> $ubootcmds
echo "nand write.raw.noverify $SPLMEMADDR 0x400000 $pagespereb" >> $ubootcmds
echo "nand write $UBOOTMEMADDR 0x800000 $ubootsize" >> $ubootcmds
echo "setenv mtdparts mtdparts=sunxi-nand.0:4m(spl),4m(spl-backup),4m(uboot),4m(env),-(UBI)" >> $ubootcmds
echo "setenv bootargs root=ubi0:rootfs rootfstype=ubifs rw earlyprintk ubi.mtd=4" >> $ubootcmds
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'" >> $ubootcmds
echo "setenv fel_booted 0" >> $ubootcmds
echo "echo Enabling Splash" >> $ubootcmds
echo "setenv stdout serial" >> $ubootcmds
echo "setenv stderr serial" >> $ubootcmds
echo "setenv splashpos m,m" >> $ubootcmds
echo "echo Configuring Video Mode" >> $ubootcmds
if [ "$PLATFORM" = "PocketCHIP" ]; then
echo "setenv video-mode" >> $ubootcmds
else
echo "setenv video-mode sunxi:640x480-24@60,monitor=composite-ntsc,overscan_x=40,overscan_y=20" >> $ubootcmds
fi
echo "saveenv" >> $ubootcmds
echo "echo going to fastboot mode" >> $ubootcmds
echo "fastboot 0" >> $ubootcmds
echo "reset" >> $ubootcmds
mkimage -A arm -T script -C none -n "flash $PLATFORM" -d $ubootcmds $ubootscr
if ! wait_for_fel; then
echo "ERROR: please make sure CHIP is connected and jumpered in FEL mode"
fi
$FEL spl $IMAGESDIR/sunxi-spl.bin
# wait for DRAM initialization to complete
sleep 1
$FEL write $UBOOTMEMADDR $IMAGESDIR/uboot-$nand_erasesize.bin
$FEL write $SPLMEMADDR $IMAGESDIR/spl-$nand_erasesize-$nand_writesize-$nand_oobsize.bin
$FEL write $UBOOTSCRMEMADDR $ubootscr
$FEL exe $UBOOTMEMADDR
if wait_for_fastboot; then
fastboot -i 0x1f3a -u flash UBI $IMAGESDIR/chip-$nand_erasesize-$nand_writesize.ubi.sparse
else
echo "failed to flash the UBI image"
fi
rm -rf $tmpdir
}
#------------------------------------------------------------
wait_for_linuxboot() {
local TIMEOUT=100
@ -79,7 +194,7 @@ ready_to_roll() {
echo " #########"
echo "### ###"
echo " # {#} #"
echo "### '\######"
echo "### '%######"
echo " # #"
echo "### ###"
echo " ########"

Loading…
Cancel
Save