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