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