xref: /openbmc/u-boot/tools/ast2600_ubimg_gen.sh (revision e1aa5c6b)
1*c16019f2SChia-Wei, Wang#!/bin/sh
2*c16019f2SChia-Wei, Wang
3*c16019f2SChia-Wei, Wangprint_usage() {
4*c16019f2SChia-Wei, Wang	echo "AST2600 UART booting Image Generator"
5*c16019f2SChia-Wei, Wang	echo ""
6*c16019f2SChia-Wei, Wang	echo "This script is used to generate a booting image with"
7*c16019f2SChia-Wei, Wang	echo "the AST2600 UART booting header pre-appended. This is"
8*c16019f2SChia-Wei, Wang	echo "mainly for recovery purpose"
9*c16019f2SChia-Wei, Wang	echo ""
10*c16019f2SChia-Wei, Wang    echo "$0 <src_img> <dst_img>"
11*c16019f2SChia-Wei, Wang    exit 1
12*c16019f2SChia-Wei, Wang}
13*c16019f2SChia-Wei, Wang
14*c16019f2SChia-Wei, Wang# check parameter
15*c16019f2SChia-Wei, Wangif [ $# -ne 2 ]
16*c16019f2SChia-Wei, Wangthen
17*c16019f2SChia-Wei, Wang    print_usage
18*c16019f2SChia-Wei, Wangfi
19*c16019f2SChia-Wei, Wang
20*c16019f2SChia-Wei, Wangsrc="$1"
21*c16019f2SChia-Wei, Wangdst="$2"
22*c16019f2SChia-Wei, Wang
23*c16019f2SChia-Wei, Wang# check src existence
24*c16019f2SChia-Wei, Wangif [ -t "$src" ]
25*c16019f2SChia-Wei, Wangthen
26*c16019f2SChia-Wei, Wang    echo "$src: No such file"
27*c16019f2SChia-Wei, Wang    exit 1
28*c16019f2SChia-Wei, Wangfi
29*c16019f2SChia-Wei, Wang
30*c16019f2SChia-Wei, Wang# get src size and round up to 4-byte align
31*c16019f2SChia-Wei, Wangsrc_sz=`wc -c < $src`
32*c16019f2SChia-Wei, Wangsrc_sz_align=$(( ((${src_sz} + 3) / 4) * 4 ))
33*c16019f2SChia-Wei, Wang
34*c16019f2SChia-Wei, Wang# output size header
35*c16019f2SChia-Wei, Wangprintf "0: %.8x" $src_sz_align | sed -E 's/0: (..)(..)(..)(..)/0: \4\3\2\1/' | xxd -r -g0 > $dst
36*c16019f2SChia-Wei, Wang
37*c16019f2SChia-Wei, Wang# output src img
38*c16019f2SChia-Wei, Wangdd if=$src of=$dst bs=1 seek=4
39*c16019f2SChia-Wei, Wang
40*c16019f2SChia-Wei, Wang# output zero padding
41*c16019f2SChia-Wei, Wangdd if=/dev/zero bs=1 count=$(( ${src_sz_align} - ${src_sz} )) >> $dst
42