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-o ==> create output file 'its_file'"
36 printf "\n\t-O ==> create config with dt overlay 'name:dtb'"
37 printf "\n\t\t(can be specified more than once)\n"
49 while getopts ":A:a:c:C:D:d:e:f:i:k:n:o:O:v:r:H:" OPTION
53 a
) LOAD_ADDR
=$OPTARG;;
55 C
) COMPRESS
=$OPTARG;;
58 e
) ENTRY_ADDR
=$OPTARG;;
59 f
) COMPATIBLE
=$OPTARG;;
64 O
) DTOVERLAY
="$DTOVERLAY ${OPTARG}";;
68 * ) echo "Invalid option passed to '$0' (options:$*)"
73 # Make sure user entered all required parameters
74 if [ -z "${ARCH}" ] || [ -z "${COMPRESS}" ] || [ -z "${LOAD_ADDR}" ] || \
75 [ -z "${ENTRY_ADDR}" ] || [ -z "${VERSION}" ] || [ -z "${KERNEL}" ] || \
76 [ -z "${OUTPUT}" ] ||
[ -z "${CONFIG}" ]; then
80 ARCH_UPPER
=$
(echo "$ARCH" |
tr '[:lower:]' '[:upper:]')
82 if [ -n "${COMPATIBLE}" ]; then
83 COMPATIBLE_PROP
="compatible = \"${COMPATIBLE}\";"
87 dtbsize
=$
(wc -c "$DTB" | cut
-d' ' -f1)
88 DTADDR
=$
(printf "0x%08x" $
(($LOAD_ADDR - $dtbsize)) )
91 # Conditionally create fdt information
92 if [ -n "${DTB}" ]; then
95 description = \"${ARCH_UPPER} OpenWrt ${DEVICE} device tree blob\";
97 data = /incbin/(\"${DTB}\");
99 ${DTADDR:+load = <${DTADDR}>;}
101 compression = \"none\";
110 FDT_PROP
="fdt = \"fdt-$FDTNUM\";"
113 if [ -n "${INITRD}" ]; then
116 description = \"${ARCH_UPPER} OpenWrt ${DEVICE} initrd\";
118 data = /incbin/(\"${INITRD}\");
130 INITRD_PROP
="ramdisk=\"initrd-${INITRDNUM}\";"
134 if [ -n "${ROOTFS}" ]; then
135 dd if="${ROOTFS}" of
="${ROOTFS}.pagesync" bs
=4096 conv
=sync
138 description = \"${ARCH_UPPER} OpenWrt ${DEVICE} rootfs\";
140 data = /incbin/(\"${ROOTFS}.pagesync\");
141 type = \"filesystem\";
143 compression = \"none\";
152 LOADABLES
="${LOADABLES:+$LOADABLES, }\"rootfs-${ROOTFSNUM}\""
155 # add DT overlay blobs
158 [ "$DTOVERLAY" ] && for overlay
in $DTOVERLAY ; do
159 overlay_blob
=${overlay##*:}
160 ovname
=${overlay%%:*}
162 ovsize
=$
(wc -c "$overlay_blob" | cut
-d' ' -f1)
163 echo "$ovname ($overlay_blob) : $ovsize" >&2
164 DTADDR
=$
(printf "0x%08x" $
(($DTADDR - $ovsize)))
165 FDTOVERLAY_NODE
="$FDTOVERLAY_NODE
168 description = \"${ARCH_UPPER} OpenWrt ${DEVICE} device tree overlay $ovname\";
170 data = /incbin/(\"${overlay_blob}\");
174 compression = \"none\";
183 OVCONFIGS
="$OVCONFIGS
186 description = \"OpenWrt ${DEVICE} with $ovname\";
187 kernel = \"kernel-1\";
188 fdt = \"fdt-$FDTNUM\", \"$ovnode\";
189 ${LOADABLES:+loadables = ${LOADABLES};}
196 # Create a default, fully populated DTS file
200 description = \"${ARCH_UPPER} OpenWrt FIT (Flattened Image Tree)\";
201 #address-cells = <1>;
205 description = \"${ARCH_UPPER} OpenWrt Linux-${VERSION}\";
206 data = /incbin/(\"${KERNEL}\");
210 compression = \"${COMPRESS}\";
211 load = <${LOAD_ADDR}>;
212 entry = <${ENTRY_ADDR}>;
227 default = \"${CONFIG}\";
229 description = \"OpenWrt ${DEVICE}\";
230 kernel = \"kernel-1\";
232 ${LOADABLES:+loadables = ${LOADABLES};}
240 # Write .its file to disk
241 echo "$DATA" > "${OUTPUT}"