tools/squashfskit: fix version detection on non-linux system
[openwrt/staging/wigyori.git] / scripts / mkits.sh
1 #!/usr/bin/env bash
2 #
3 # Licensed under the terms of the GNU GPL License version 2 or later.
4 #
5 # Author: Peter Tyser <ptyser@xes-inc.com>
6 #
7 # U-Boot firmware supports the booting of images in the Flattened Image
8 # Tree (FIT) format. The FIT format uses a device tree structure to
9 # describe a kernel image, device tree blob, ramdisk, etc. This script
10 # creates an Image Tree Source (.its file) which can be passed to the
11 # 'mkimage' utility to generate an Image Tree Blob (.itb file). The .itb
12 # file can then be booted by U-Boot (or other bootloaders which support
13 # FIT images). See doc/uImage.FIT/howto.txt in U-Boot source code for
14 # additional information on FIT images.
15 #
16
17 usage() {
18 echo "Usage: `basename $0` -A arch -C comp -a addr -e entry" \
19 "-v version -k kernel [-D name -d dtb] -o its_file"
20 echo -e "\t-A ==> set architecture to 'arch'"
21 echo -e "\t-C ==> set compression type 'comp'"
22 echo -e "\t-c ==> set config name 'config'"
23 echo -e "\t-a ==> set load address to 'addr' (hex)"
24 echo -e "\t-e ==> set entry point to 'entry' (hex)"
25 echo -e "\t-v ==> set kernel version to 'version'"
26 echo -e "\t-k ==> include kernel image 'kernel'"
27 echo -e "\t-D ==> human friendly Device Tree Blob 'name'"
28 echo -e "\t-d ==> include Device Tree Blob 'dtb'"
29 echo -e "\t-o ==> create output file 'its_file'"
30 exit 1
31 }
32
33 while getopts ":A:a:c:C:D:d:e:k:o:v:" OPTION
34 do
35 case $OPTION in
36 A ) ARCH=$OPTARG;;
37 a ) LOAD_ADDR=$OPTARG;;
38 c ) CONFIG=$OPTARG;;
39 C ) COMPRESS=$OPTARG;;
40 D ) DEVICE=$OPTARG;;
41 d ) DTB=$OPTARG;;
42 e ) ENTRY_ADDR=$OPTARG;;
43 k ) KERNEL=$OPTARG;;
44 o ) OUTPUT=$OPTARG;;
45 v ) VERSION=$OPTARG;;
46 * ) echo "Invalid option passed to '$0' (options:$@)"
47 usage;;
48 esac
49 done
50
51 # Make sure user entered all required parameters
52 if [ -z "${ARCH}" ] || [ -z "${COMPRESS}" ] || [ -z "${LOAD_ADDR}" ] || \
53 [ -z "${ENTRY_ADDR}" ] || [ -z "${VERSION}" ] || [ -z "${KERNEL}" ] || \
54 [ -z "${OUTPUT}" ] || [ -z "${CONFIG}" ]; then
55 usage
56 fi
57
58 ARCH_UPPER=`echo $ARCH | tr '[:lower:]' '[:upper:]'`
59
60 # Conditionally create fdt information
61 if [ -n "${DTB}" ]; then
62 FDT="
63 fdt@1 {
64 description = \"${ARCH_UPPER} OpenWrt ${DEVICE} device tree blob\";
65 data = /incbin/(\"${DTB}\");
66 type = \"flat_dt\";
67 arch = \"${ARCH}\";
68 compression = \"none\";
69 hash@1 {
70 algo = \"crc32\";
71 };
72 hash@2 {
73 algo = \"sha1\";
74 };
75 };
76 "
77 fi
78
79 # Create a default, fully populated DTS file
80 DATA="/dts-v1/;
81
82 / {
83 description = \"${ARCH_UPPER} OpenWrt FIT (Flattened Image Tree)\";
84 #address-cells = <1>;
85
86 images {
87 kernel@1 {
88 description = \"${ARCH_UPPER} OpenWrt Linux-${VERSION}\";
89 data = /incbin/(\"${KERNEL}\");
90 type = \"kernel\";
91 arch = \"${ARCH}\";
92 os = \"linux\";
93 compression = \"${COMPRESS}\";
94 load = <${LOAD_ADDR}>;
95 entry = <${ENTRY_ADDR}>;
96 hash@1 {
97 algo = \"crc32\";
98 };
99 hash@2 {
100 algo = \"sha1\";
101 };
102 };
103
104 ${FDT}
105
106 };
107
108 configurations {
109 default = \"${CONFIG}\";
110 ${CONFIG} {
111 description = \"OpenWrt\";
112 kernel = \"kernel@1\";
113 fdt = \"fdt@1\";
114 };
115 };
116 };"
117
118 # Write .its file to disk
119 echo "$DATA" > ${OUTPUT}