3 # Licensed under the terms of the GNU GPL License version 2 or later.
5 # Author: Peter Tyser <ptyser@xes-inc.com>
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.
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"
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-f ==> set device tree compatible string"
27 printf "\n\t-i ==> include initrd Blob 'initrd'"
28 printf "\n\t-v ==> set kernel version to 'version'"
29 printf "\n\t-k ==> include kernel image 'kernel'"
30 printf "\n\t-D ==> human friendly Device Tree Blob 'name'"
31 printf "\n\t-n ==> fdt unit-address 'address'"
32 printf "\n\t-d ==> include Device Tree Blob 'dtb'"
33 printf "\n\t-r ==> include RootFS blob 'rootfs'"
34 printf "\n\t-H ==> specify hash algo instead of SHA1"
35 printf "\n\t-l ==> legacy mode character (@ etc otherwise -)"
36 printf "\n\t-o ==> create output file 'its_file'"
37 printf "\n\t-O ==> create config with dt overlay 'name:dtb'"
38 printf "\n\t\t(can be specified more than once)\n"
51 while getopts ":A:a:c:C:D:d:e:f:i:k:l:n:o:O:v:r:H:" OPTION
55 a
) LOAD_ADDR
=$OPTARG;;
57 C
) COMPRESS
=$OPTARG;;
60 e
) ENTRY_ADDR
=$OPTARG;;
61 f
) COMPATIBLE
=$OPTARG;;
64 l
) REFERENCE_CHAR
=$OPTARG;;
67 O
) DTOVERLAY
="$DTOVERLAY ${OPTARG}";;
71 * ) echo "Invalid option passed to '$0' (options:$*)"
76 # Make sure user entered all required parameters
77 if [ -z "${ARCH}" ] || [ -z "${COMPRESS}" ] || [ -z "${LOAD_ADDR}" ] || \
78 [ -z "${ENTRY_ADDR}" ] || [ -z "${VERSION}" ] || [ -z "${KERNEL}" ] || \
79 [ -z "${OUTPUT}" ] ||
[ -z "${CONFIG}" ]; then
83 ARCH_UPPER
=$
(echo "$ARCH" |
tr '[:lower:]' '[:upper:]')
85 if [ -n "${COMPATIBLE}" ]; then
86 COMPATIBLE_PROP
="compatible = \"${COMPATIBLE}\";"
90 dtbsize
=$
(wc -c "$DTB" | cut
-d' ' -f1)
91 DTADDR
=$
(printf "0x%08x" $
(($LOAD_ADDR - $dtbsize)) )
94 # Conditionally create fdt information
95 if [ -n "${DTB}" ]; then
97 fdt${REFERENCE_CHAR}$FDTNUM {
98 description = \"${ARCH_UPPER} OpenWrt ${DEVICE} device tree blob\";
100 data = /incbin/(\"${DTB}\");
102 ${DTADDR:+load = <${DTADDR}>;}
104 compression = \"none\";
113 FDT_PROP
="fdt = \"fdt${REFERENCE_CHAR}$FDTNUM\";"
116 if [ -n "${INITRD}" ]; then
118 initrd${REFERENCE_CHAR}$INITRDNUM {
119 description = \"${ARCH_UPPER} OpenWrt ${DEVICE} initrd\";
121 data = /incbin/(\"${INITRD}\");
133 INITRD_PROP
="ramdisk=\"initrd${REFERENCE_CHAR}${INITRDNUM}\";"
137 if [ -n "${ROOTFS}" ]; then
138 dd if="${ROOTFS}" of
="${ROOTFS}.pagesync" bs
=4096 conv
=sync
140 rootfs${REFERENCE_CHAR}$ROOTFSNUM {
141 description = \"${ARCH_UPPER} OpenWrt ${DEVICE} rootfs\";
143 data = /incbin/(\"${ROOTFS}.pagesync\");
144 type = \"filesystem\";
146 compression = \"none\";
155 LOADABLES
="${LOADABLES:+$LOADABLES, }\"rootfs${REFERENCE_CHAR}${ROOTFSNUM}\""
158 # add DT overlay blobs
161 [ "$DTOVERLAY" ] && for overlay
in $DTOVERLAY ; do
162 overlay_blob
=${overlay##*:}
163 ovname
=${overlay%%:*}
165 ovsize
=$
(wc -c "$overlay_blob" | cut
-d' ' -f1)
166 echo "$ovname ($overlay_blob) : $ovsize" >&2
167 DTADDR
=$
(printf "0x%08x" $
(($DTADDR - $ovsize)))
168 FDTOVERLAY_NODE
="$FDTOVERLAY_NODE
171 description = \"${ARCH_UPPER} OpenWrt ${DEVICE} device tree overlay $ovname\";
173 data = /incbin/(\"${overlay_blob}\");
177 compression = \"none\";
186 OVCONFIGS
="$OVCONFIGS
189 description = \"OpenWrt ${DEVICE} with $ovname\";
190 kernel = \"kernel${REFERENCE_CHAR}1\";
191 fdt = \"fdt${REFERENCE_CHAR}$FDTNUM\", \"$ovnode\";
192 ${LOADABLES:+loadables = ${LOADABLES};}
199 # Create a default, fully populated DTS file
203 description = \"${ARCH_UPPER} OpenWrt FIT (Flattened Image Tree)\";
204 #address-cells = <1>;
207 kernel${REFERENCE_CHAR}1 {
208 description = \"${ARCH_UPPER} OpenWrt Linux-${VERSION}\";
209 data = /incbin/(\"${KERNEL}\");
213 compression = \"${COMPRESS}\";
214 load = <${LOAD_ADDR}>;
215 entry = <${ENTRY_ADDR}>;
230 default = \"${CONFIG}\";
232 description = \"OpenWrt ${DEVICE}\";
233 kernel = \"kernel${REFERENCE_CHAR}1\";
235 ${LOADABLES:+loadables = ${LOADABLES};}
243 # Write .its file to disk
244 echo "$DATA" > "${OUTPUT}"