2016-12-01 18:42:47 -05:00
|
|
|
|
#!/bin/bash
|
2016-10-27 18:40:12 -04:00
|
|
|
|
|
|
|
|
|
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"
|
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
|
|
|
|
|
|
|
|
|
if [ "$oobsize" = "100" ]; then
|
|
|
|
|
#TOSH_512_SLC
|
2016-12-01 18:42:47 -05:00
|
|
|
|
volspec="vol_flags=autoresize"
|
2016-12-01 17:36:10 -05:00
|
|
|
|
elif [ "$oobsize" = "500" ]; then
|
|
|
|
|
#TOSH_4GB_MLC
|
2016-12-01 18:42:47 -05:00
|
|
|
|
volspec="vol_size=3584MiB"
|
2016-12-01 17:36:10 -05:00
|
|
|
|
else
|
|
|
|
|
#HYNI_8GB_MLC
|
2016-12-01 19:19:29 -05:00
|
|
|
|
volspec="vol_size=7168MiB"
|
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
|
|
|
|
|
mkfs.ubifs -d $rootfs -m $pagesize -e $lebsize -c $maxlebcount -o $ubifs
|
|
|
|
|
echo "[rootfs]
|
|
|
|
|
mode=ubi
|
|
|
|
|
vol_id=0
|
2016-12-01 18:42:47 -05:00
|
|
|
|
$vol_spec
|
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
|
|
|
|
|
|
|
|
|
|
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:
|
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
|