2016-12-21 18:00:38 -05:00
|
|
|
|
#!/bin/bash
|
2016-10-27 18:40:12 -04:00
|
|
|
|
|
|
|
|
|
SCRIPTDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
|
|
|
|
source $SCRIPTDIR/common.sh
|
|
|
|
|
|
2016-12-21 18:00:38 -05:00
|
|
|
|
if [[ -z $(which ${MKFS_UBIFS}) ]]; then
|
|
|
|
|
echo "Could not find ${MKFS_UBIFS} in path."
|
|
|
|
|
echo "Install it with the CHIP-SDK setup script."
|
|
|
|
|
echo "You will also need to run this script as root."
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2016-10-27 18:40:12 -04:00
|
|
|
|
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"
|
2016-12-01 17:36:10 -05:00
|
|
|
|
local oobsize="$8"
|
2016-10-27 18:40:12 -04:00
|
|
|
|
local ebsize=`printf %x $eraseblocksize`
|
|
|
|
|
local psize=`printf %x $pagesize`
|
2016-12-01 17:36:10 -05:00
|
|
|
|
local osize=`printf %x $oobsize`
|
|
|
|
|
local ubi=$outputdir/chip-$ebsize-$psize-$osize.ubi
|
|
|
|
|
local sparseubi=$outputdir/chip-$ebsize-$psize-$osize.ubi.sparse
|
2016-10-27 18:40:12 -04:00
|
|
|
|
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
|
2016-12-01 17:36:10 -05:00
|
|
|
|
|
2016-12-01 19:30:55 -05:00
|
|
|
|
if [ "$osize" = "100" ]; then
|
2016-12-01 17:36:10 -05:00
|
|
|
|
#TOSH_512_SLC
|
2016-12-01 18:42:47 -05:00
|
|
|
|
volspec="vol_flags=autoresize"
|
2016-12-01 19:30:55 -05:00
|
|
|
|
elif [ "$osize" = "500" ]; then
|
2016-12-01 17:36:10 -05:00
|
|
|
|
#TOSH_4GB_MLC
|
2016-12-01 18:42:47 -05:00
|
|
|
|
volspec="vol_size=3584MiB"
|
2016-12-01 19:44:40 -05:00
|
|
|
|
elif [ "$osize" = "680" ]; then
|
2016-12-01 17:36:10 -05:00
|
|
|
|
#HYNI_8GB_MLC
|
2016-12-01 19:19:29 -05:00
|
|
|
|
volspec="vol_size=7168MiB"
|
2016-12-01 19:39:53 -05:00
|
|
|
|
else
|
|
|
|
|
echo "Unable to acquire appropriate volume size or flags, quitting!"
|
|
|
|
|
exit 1
|
2016-12-01 17:36:10 -05:00
|
|
|
|
fi
|
2016-10-27 18:40:12 -04:00
|
|
|
|
|
|
|
|
|
mkdir -p $rootfs
|
|
|
|
|
tar -xf $rootfstar -C $rootfs
|
2016-12-21 18:00:38 -05:00
|
|
|
|
${MKFS_UBIFS} -d $rootfs -m $pagesize -e $lebsize -c $maxlebcount -o $ubifs
|
2016-10-27 18:40:12 -04:00
|
|
|
|
echo "[rootfs]
|
|
|
|
|
mode=ubi
|
|
|
|
|
vol_id=0
|
2016-12-01 20:06:13 -05:00
|
|
|
|
$volspec
|
2016-10-27 18:40:12 -04:00
|
|
|
|
vol_type=dynamic
|
|
|
|
|
vol_name=rootfs
|
|
|
|
|
vol_alignment=1
|
|
|
|
|
image=$ubifs" > $ubicfg
|
|
|
|
|
|
2016-12-01 17:36:10 -05:00
|
|
|
|
|
2016-10-27 18:40:12 -04:00
|
|
|
|
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
|
|
|
|
|
|
2016-12-21 18:00:38 -05:00
|
|
|
|
${SNIB} -c 64/1024 -p $pagesize -o $oobsize -u 1024 -e $eraseblocksize -b -s $spl $nandspl
|
2016-10-27 18:40:12 -04:00
|
|
|
|
|
|
|
|
|
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
|
2016-12-21 18:00:38 -05:00
|
|
|
|
${SNIB} -c 64/1024 -p $pagesize -o $oobsize -u 1024 -e $eraseblocksize -b -s $padding $splpadding
|
2016-10-27 18:40:12 -04:00
|
|
|
|
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:
|
2016-12-01 17:36:10 -05:00
|
|
|
|
prepare_ubi $OUTPUTDIR $ROOTFSTAR "slc" 2048 262144 4096 1024 256
|
|
|
|
|
# Toshiba MLC image:
|
|
|
|
|
prepare_ubi $OUTPUTDIR $ROOTFSTAR "mlc" 4096 4194304 16384 16384 1280
|
|
|
|
|
# Hynix MLC image:
|
|
|
|
|
prepare_ubi $OUTPUTDIR $ROOTFSTAR "mlc" 4096 4194304 16384 16384 1664
|
2016-10-27 18:40:12 -04:00
|
|
|
|
|
|
|
|
|
## 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
|