62cfc21c6b87e4f010585aabe1060325dd15888e
[openwrt/openwrt.git] / scripts / mkits.sh
1 #!/bin/sh
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 printf "Usage: %s -A arch -C comp -a addr -e entry -v version"\
19 "-k kernel [-D name -d dtb] -o its_file" "$(basename $0)"
20 printf "\n\t-A ==> set architecture to 'arch'"
21 printf "\n\t-C ==> set compression type 'comp'"
22 printf "\n\t-c ==> set config name 'config'"
23 printf "\n\t-a ==> set load address to 'addr' (hex)"
24 printf "\n\t-e ==> set entry point to 'entry' (hex)"
25 printf "\n\t-v ==> set kernel version to 'version'"
26 printf "\n\t-k ==> include kernel image 'kernel'"
27 printf "\n\t-D ==> human friendly Device Tree Blob 'name'"
28 printf "\n\t-d ==> include Device Tree Blob 'dtb'"
29 printf "\n\t-o ==> create output file 'its_file'\n"
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_NODE="
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 FDT_PROP="fdt = \"fdt@1\";"
78 fi
79
80 # Create a default, fully populated DTS file
81 DATA="/dts-v1/;
82
83 / {
84 description = \"${ARCH_UPPER} OpenWrt FIT (Flattened Image Tree)\";
85 #address-cells = <1>;
86
87 images {
88 kernel@1 {
89 description = \"${ARCH_UPPER} OpenWrt Linux-${VERSION}\";
90 data = /incbin/(\"${KERNEL}\");
91 type = \"kernel\";
92 arch = \"${ARCH}\";
93 os = \"linux\";
94 compression = \"${COMPRESS}\";
95 load = <${LOAD_ADDR}>;
96 entry = <${ENTRY_ADDR}>;
97 hash@1 {
98 algo = \"crc32\";
99 };
100 hash@2 {
101 algo = \"sha1\";
102 };
103 };
104 ${FDT_NODE}
105 };
106
107 configurations {
108 default = \"${CONFIG}\";
109 ${CONFIG} {
110 description = \"OpenWrt\";
111 kernel = \"kernel@1\";
112 ${FDT_PROP}
113 };
114 };
115 };"
116
117 # Write .its file to disk
118 echo "$DATA" > "${OUTPUT}"