xref: /rk3399_rockchip-uboot/scripts/uboot.sh (revision d3acdc96e2fd0ed34beb32b26ba57131a1e04ea3)
1#!/bin/bash
2#
3# Copyright (c) 2020 Rockchip Electronics Co., Ltd
4#
5# SPDX-License-Identifier: GPL-2.0
6#
7
8if [ $# -eq 0 ]; then
9	echo "ERROR: No args of $0"
10	exit 1
11fi
12
13while [ $# -gt 0 ]; do
14	case $1 in
15		--load)
16			LOAD_ADDR=$2
17			shift 2
18			;;
19		--size)
20			SIZE="$1 $2 $3"
21			shift 3
22			;;
23		*)
24			echo "ERROR: Unknown arg: $1"
25			exit 1
26			;;
27	esac
28done
29
30rm uboot.img -f
31
32if [ -z "${LOAD_ADDR}" ]; then
33	echo "ERROR: No load address"
34	exit 1
35fi
36
37HEAD_KB=2
38BIN_KB=`ls -l u-boot.bin | awk '{ print $5 }'`
39if [ -z "${SIZE}" ]; then
40	MAX_KB=1046528
41else
42	MAX_KB=`echo ${SIZE} | awk '{print strtonum($2)}'`
43	MAX_KB=$(((MAX_KB-HEAD_KB)*1024))
44fi
45
46if [ ${BIN_KB} -gt ${MAX_KB} ]; then
47	echo "ERROR: pack uboot failed! u-boot.bin actual: ${BIN_KB} bytes, max limit: ${MAX_KB} bytes"
48	exit 1
49fi
50
51./tools/loaderimage --pack --uboot u-boot.bin uboot.img ${LOAD_ADDR} ${SIZE}
52echo "pack uboot okay! Input: u-boot.bin"
53echo
54