build: add elecom-product-header for ELECOM devices
[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" "$(basename "$0")"
19 printf " -v version -k kernel [-D name -n address -d dtb] -o its_file"
20
21 printf "\n\t-A ==> set architecture to 'arch'"
22 printf "\n\t-C ==> set compression type 'comp'"
23 printf "\n\t-c ==> set config name 'config'"
24 printf "\n\t-a ==> set load address to 'addr' (hex)"
25 printf "\n\t-e ==> set entry point to 'entry' (hex)"
26 printf "\n\t-v ==> set kernel version to 'version'"
27 printf "\n\t-k ==> include kernel image 'kernel'"
28 printf "\n\t-D ==> human friendly Device Tree Blob 'name'"
29 printf "\n\t-n ==> fdt unit-address 'address'"
30 printf "\n\t-d ==> include Device Tree Blob 'dtb'"
31 printf "\n\t-o ==> create output file 'its_file'\n"
32 exit 1
33 }
34
35 FDTNUM=1
36
37 while getopts ":A:a:c:C:D:d:e:k:n:o:v:" OPTION
38 do
39 case $OPTION in
40 A ) ARCH=$OPTARG;;
41 a ) LOAD_ADDR=$OPTARG;;
42 c ) CONFIG=$OPTARG;;
43 C ) COMPRESS=$OPTARG;;
44 D ) DEVICE=$OPTARG;;
45 d ) DTB=$OPTARG;;
46 e ) ENTRY_ADDR=$OPTARG;;
47 k ) KERNEL=$OPTARG;;
48 n ) FDTNUM=$OPTARG;;
49 o ) OUTPUT=$OPTARG;;
50 v ) VERSION=$OPTARG;;
51 * ) echo "Invalid option passed to '$0' (options:$*)"
52 usage;;
53 esac
54 done
55
56 # Make sure user entered all required parameters
57 if [ -z "${ARCH}" ] || [ -z "${COMPRESS}" ] || [ -z "${LOAD_ADDR}" ] || \
58 [ -z "${ENTRY_ADDR}" ] || [ -z "${VERSION}" ] || [ -z "${KERNEL}" ] || \
59 [ -z "${OUTPUT}" ] || [ -z "${CONFIG}" ]; then
60 usage
61 fi
62
63 ARCH_UPPER=$(echo "$ARCH" | tr '[:lower:]' '[:upper:]')
64
65 # Conditionally create fdt information
66 if [ -n "${DTB}" ]; then
67 FDT_NODE="
68 fdt@$FDTNUM {
69 description = \"${ARCH_UPPER} OpenWrt ${DEVICE} device tree blob\";
70 data = /incbin/(\"${DTB}\");
71 type = \"flat_dt\";
72 arch = \"${ARCH}\";
73 compression = \"none\";
74 hash@1 {
75 algo = \"crc32\";
76 };
77 hash@2 {
78 algo = \"sha1\";
79 };
80 };
81 "
82 FDT_PROP="fdt = \"fdt@$FDTNUM\";"
83 fi
84
85 # Create a default, fully populated DTS file
86 DATA="/dts-v1/;
87
88 / {
89 description = \"${ARCH_UPPER} OpenWrt FIT (Flattened Image Tree)\";
90 #address-cells = <1>;
91
92 images {
93 kernel@1 {
94 description = \"${ARCH_UPPER} OpenWrt Linux-${VERSION}\";
95 data = /incbin/(\"${KERNEL}\");
96 type = \"kernel\";
97 arch = \"${ARCH}\";
98 os = \"linux\";
99 compression = \"${COMPRESS}\";
100 load = <${LOAD_ADDR}>;
101 entry = <${ENTRY_ADDR}>;
102 hash@1 {
103 algo = \"crc32\";
104 };
105 hash@2 {
106 algo = \"sha1\";
107 };
108 };
109 ${FDT_NODE}
110 };
111
112 configurations {
113 default = \"${CONFIG}\";
114 ${CONFIG} {
115 description = \"OpenWrt\";
116 kernel = \"kernel@1\";
117 ${FDT_PROP}
118 };
119 };
120 };"
121
122 # Write .its file to disk
123 echo "$DATA" > "${OUTPUT}"