summaryrefslogtreecommitdiffstats
path: root/scripts/mkits-qsdk-ipq-image.sh
blob: 8f7f42269167ecb37581b0c9f275d4adb7eff29b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env bash
#
# Licensed under the terms of the GNU GPL License version 2 or later.
# Author: Piotr Dymacz <pepe2k@gmail.com>, based on mkits.sh.
#
# Qualcomm SDK (QSDK) sysupgrade compatible images for IPQ40xx, IPQ806x
# and IPQ807x use FIT format together with 'dumpimage' tool from U-Boot
# for verifying and extracting them. Based on 'images' sections names,
# corresponding mtd partitions are flashed.
# This is a simple script for generating FIT images tree source files,
# compatible with the QSDK sysupgrade format. Resulting images can be
# used for initial (factory -> OpenWrt) installation and would work
# both in CLI and GUI. The script is also universal in a way it allows
# to include as many sections as needed.
#

usage() {
	echo "Usage: `basename $0` output [[device].bootscript] img0_name img0_file [[img1_name img1_file] ...]"
	exit 1
}

# We need at least 3 arguments
[ "$#" -lt 3 ] && usage || node_type="firmware"

# Target output file
OUTPUT="$1"; shift

# check for bootscript
[ "${1##*.}" = "bootscript" ] && has_script=true && node_type="script"

# Create a default, fully populated DTS file
echo "\
/dts-v1/;

/ {
	description = \"OpenWrt factory image\";
	#address-cells = <1>;

	images {" > ${OUTPUT}

while [ -n "$1" -a -n "$2" ] || [ $has_script ]; do
	[ -f "$2" ] || [ $has_script ] && has_script= || usage

	case "$node_type" in
	script)
		name="$node_type"
		file="$1"; shift
		desc="${file%.*} uboot ${file##*.}"
		type="$node_type"
		node_type="firmware"
	;;
	firmware)
		name="$1"; shift
		file="$1"; shift
		desc="$name"
		type="$node_type"
	;;
	esac

	echo \
"		${name} {
			description = \"${desc}\";
			data = /incbin/(\"${file}\");
			type = \"${type}\";
			arch = \"ARM\";
			compression = \"none\";
			hash@1 {
				algo = \"crc32\";
			};
		};" >> ${OUTPUT}
done

echo \
"	};
};" >> ${OUTPUT}