5 function write_hex_to_4bytes_binary()
17 for str in $(echo $HEX | sed 's/../& /g' | rev); do
18 str=$(echo -en $str | rev)
23 function write_to_4bytes_binary()
25 HEX=`echo "obase=16; $1" | bc`
27 write_hex_to_4bytes_binary $HEX $2
30 function write_to_padding_binary()
34 PAD_SIZE=$(($(($PAD - $(($1 % $PAD)))) % $PAD))
35 if [ $PAD_SIZE -gt 0 ]; then
36 dd if=/dev/zero of=./padding bs=1 count=$PAD_SIZE 2>/dev/zero
41 if [ "${VERBOSE}" -eq "1" ]; then
42 echo -en " | PAD: $PAD_SIZE[B]\n"
46 function get_dtb_size()
48 SIZE=`du -b $1 | awk '{print $1}'`
49 PAD_SIZE=$(($(($PAD - $(($SIZE % $PAD)))) % $PAD))
50 DTB_SIZE=$(($SIZE + $PAD_SIZE))
54 echo "sprd_dtbtool.sh [OPTIONS] -o <output file> <input DTB path>"
56 echo " --output-file/-o output file"
57 echo " --dtc-path/-p path to dtc"
58 echo " --page-size/-s page size in bytes"
59 echo " --verbose/-v verbose"
60 echo " --help/-h this help screen"
69 OUT_DIR="./arch/arm/boot"
78 let MAX_PAD_SIZE=1024*1024
82 if [ "$#" -eq "0" ]; then
88 params="$(getopt -o o:p:s:vh -l output-file:,dtc-path:,page-size:,verbose,help --name "$0" -- "$@")"
96 OUT_DIR=`dirname $OUTPUT_FILE`
97 if [ ! -d "$OUT_DIR" ]; then
98 echo "invalid output path '$OUT_DIR'."
101 OUT=${OUTPUT_FILE#${OUT_DIR}}
114 # page size should be number, and larger than 0, and smaller than 1024*1024
115 if [ ! -z "$R" ] || [ "$PAD" -lt "0" ] || [ "$PAD" -gt "$MAX_PAD_SIZE" ]; then
116 echo "invalid page size."
137 if [ "$#" -eq "0" ]; then
142 DTS_DIR=${DTS_DIR%\/}
143 if [ ! -d "$DTS_DIR" ]; then
144 echo "invalid DTB input path '$DTS_DIR'."
147 DTB=(`find ${DTS_DIR} -name "*.dtb"`)
148 for i in ${DTB[*]}; do
150 TAG_CHECK=`${DTC_PATH}/dtc -I dtb -O dts $i 2>/dev/null | grep "${SPRD_TAG}"`
151 if [ "z${TAG_CHECK}" == "z" ]; then
152 # no tag in the dtb file
159 if [ ! -f "$DTC_PATH/dtc" ]; then
160 echo "no DTC file in '$DTC_PATH'."
164 if [ "${VERBOSE}" -eq "1" ]; then
165 echo "DTB input path is '${DTS_DIR}'"
166 echo "output path is '${OUT_DIR}', output file is '${OUT}'"
167 echo "page size is '${PAD}'"
177 HEADER_SIZE=$((12 + 20 * $DTB_CNT + 4))
180 if [ "${VERBOSE}" -eq "1" ]; then
182 echo -en "$HEADER_SIZE[B]\n"
185 echo -en $SPRD_MAGIC > $OUT
187 write_to_4bytes_binary $SPRD_VERSION $OUT
189 write_to_4bytes_binary $DTB_CNT $OUT
192 for i in ${DTB[*]}; do
194 if [ -e $FILE ]; then
195 TAG_CHECK=`${DTC_PATH}/dtc -I dtb -O dts $i 2>/dev/null | grep "${SPRD_TAG}"`
196 TAG_CHECK=${TAG_CHECK#*<}
197 TAG_CHECK=${TAG_CHECK%>*}
198 CHIPSET=`echo ${TAG_CHECK} | awk '{ print $1 }'`
199 PLATFORM=`echo ${TAG_CHECK} | awk '{ print $2 }'`
200 REV=`echo ${TAG_CHECK} | awk '{ print $3 }'`
202 write_hex_to_4bytes_binary $CHIPSET $OUT
205 write_hex_to_4bytes_binary $PLATFORM $OUT
208 write_hex_to_4bytes_binary $REV $OUT
211 write_to_4bytes_binary $DTB_OFFSET $OUT
215 write_to_4bytes_binary $DTB_SIZE $OUT
218 DTB_OFFSET=$(($DTB_OFFSET + $DTB_SIZE))
220 echo -en "$i not found.\nexit\n"
225 write_to_4bytes_binary $ENDOFHEADER $OUT
228 write_to_padding_binary $HEADER_SIZE
229 cat $OUT_TMP padding > $OUT
233 for i in ${DTB[*]}; do
235 if [ -e $FILE ]; then
237 SIZE=`du -b $FILE | awk '{print $1}'`
239 cat $OUT $FILE > $OUT_TMP
240 if [ "${VERBOSE}" -eq "1" ]; then
242 echo -en "$SIZE[B]\n"
245 write_to_padding_binary $SIZE
246 cat $OUT_TMP padding > $OUT
248 echo -en "$i not found.\nexit\n"
260 S=`du -b $OUT_DIR/$OUT | awk '{print $1}'`
262 if [ "${VERBOSE}" -eq "1" ]; then
263 echo -en "## OUT: $OUT size: $S[B]; $S_K[KB]\n"
265 echo "$OUT_DIR/$OUT (size: ${S_K}KB) is created."