xref: /OK3568_Linux_fs/u-boot/scripts/android2fit.sh (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1#!/bin/bash
2#
3# Copyright (c) 2020 Rockchip Electronics Co., Ltd
4#
5# SPDX-License-Identifier: GPL-2.0
6#
7set -e
8
9OUT="out"
10
11function usage()
12{
13	echo
14	echo "usage:"
15	echo "    $0 -f [Android boot.img] -o [FIT boot.img]"
16	echo
17}
18
19function args_process()
20{
21	if [ $# -ne 4 ]; then
22		usage
23		exit 1
24	fi
25
26	while [ $# -gt 0 ]; do
27		case $1 in
28			-f)
29				BOOT_IMG=$2
30				shift 2
31				;;
32			-o)
33				FIT_IMG=$2
34				shift 2
35				;;
36			*)
37				usage
38				exit 1
39				;;
40		esac
41	done
42
43	if [ ! -f ${BOOT_IMG} ]; then
44		echo "ERROR: No ${ITB}"
45		exit 1
46	fi
47}
48
49function android2fit()
50{
51	if ! file ${BOOT_IMG} | grep "Android bootimg" ; then
52		echo "ERROR: ${BOOT_IMG} is not an Android Image"
53		file ${BOOT_IMG}
54		exit 1
55	fi
56
57	rm ${OUT}/ -rf
58	./scripts/unpack_bootimg --boot_img ${BOOT_IMG} --out ${OUT}/
59	./scripts/unpack_resource.sh ${OUT}/second  ${OUT}/
60	mv ${OUT}/second ${OUT}/resource
61
62	rm images/ -rf && mkdir -p images/
63	cp ${OUT}/kernel images/
64	cp ${OUT}/resource images/second
65	cp ${OUT}/ramdisk images/
66	cp ${OUT}/rk-kernel.dtb images/dtb
67	rm ${OUT}/ -rf
68
69	./make.sh fit
70	if [ "boot.img" != ${FIT_IMG} ]; then
71		mv boot.img ${FIT_IMG}
72	fi
73
74	echo "Transform OK: Android(${BOOT_IMG}) ==> FIT(${FIT_IMG}) is ready"
75	echo
76}
77
78args_process $*
79android2fit
80