forked from alxgcrz/chip-tools
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 75803f2
Showing
14 changed files
with
1,573 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright (c) <2016> <Next Thing Co.> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# CHIP-tools | ||
A collection of scripts for working with CHIP | ||
|
||
## Requirements | ||
1) **sunxi-tools** from your package manager or from the [Sunxi repository](https://github.com/linux-sunxi/sunxi-tools.git) | ||
2) **uboot-tools** from your package manager | ||
2) **mtd-utils-mlc** from our repository (https://github.com/nextthingco/chip-mtd-utils) [for creating images] | ||
|
||
## Included Tools | ||
### chip-update-firmware | ||
This tool is used to download and flash the latest firmware release for CHIP. The tool also now only supports fastboot flashing. | ||
|
||
### chip-create-nand-images | ||
This tool is used to generate local firmware images for CHIP and CHIP Pro. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
#!/bin/bash | ||
|
||
SCRIPTDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) | ||
source $SCRIPTDIR/common.sh | ||
|
||
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 | ||
|
||
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 oobsize="$8" | ||
local ebsize=`printf %x $eraseblocksize` | ||
local psize=`printf %x $pagesize` | ||
local osize=`printf %x $oobsize` | ||
local ubi=$outputdir/chip-$ebsize-$psize-$osize.ubi | ||
local sparseubi=$outputdir/chip-$ebsize-$psize-$osize.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 | ||
|
||
if [ "$osize" = "100" ]; then | ||
#TOSH_512_SLC | ||
volspec="vol_flags=autoresize" | ||
elif [ "$osize" = "500" ]; then | ||
#TOSH_4GB_MLC | ||
volspec="vol_size=3584MiB" | ||
elif [ "$osize" = "680" ]; then | ||
#HYNI_8GB_MLC | ||
volspec="vol_size=7168MiB" | ||
else | ||
echo "Unable to acquire appropriate volume size or flags, quitting!" | ||
exit 1 | ||
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 | ||
$volspec | ||
vol_type=dynamic | ||
vol_name=rootfs | ||
vol_alignment=1 | ||
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 | ||
|
||
${SNIB} -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 | ||
${SNIB} -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 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 | ||
|
||
## 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 |
Oops, something went wrong.