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-s ==> set FDT load address to 'addr' (hex)"
39 printf "\n\t\t(can be specified more than once)\n"
52 while getopts ":A:a:c:C:D:d:e:f:i:k:l:n:o:O:v:r:s:H:" OPTION
56 a
) LOAD_ADDR
=$OPTARG;;
58 C
) COMPRESS
=$OPTARG;;
61 e
) ENTRY_ADDR
=$OPTARG;;
62 f
) COMPATIBLE
=$OPTARG;;
65 l
) REFERENCE_CHAR
=$OPTARG;;
68 O
) DTOVERLAY
="$DTOVERLAY ${OPTARG}";;
73 * ) echo "Invalid option passed to '$0' (options:$*)"
78 # Make sure user entered all required parameters
79 if [ -z "${ARCH}" ] || [ -z "${COMPRESS}" ] || [ -z "${LOAD_ADDR}" ] || \
80 [ -z "${ENTRY_ADDR}" ] || [ -z "${VERSION}" ] || [ -z "${KERNEL}" ] || \
81 [ -z "${OUTPUT}" ] ||
[ -z "${CONFIG}" ]; then
85 ARCH_UPPER
=$
(echo "$ARCH" |
tr '[:lower:]' '[:upper:]')
87 if [ -n "${COMPATIBLE}" ]; then
88 COMPATIBLE_PROP
="compatible = \"${COMPATIBLE}\";"
92 dtbsize
=$
(wc -c "$DTB" |
awk '{print $1}')
93 DTADDR
=$
(printf "0x%08x" $
(($LOAD_ADDR - $dtbsize)) )
100 # Conditionally create fdt information
101 if [ -n "${DTB}" ]; then
103 fdt${REFERENCE_CHAR}$FDTNUM {
104 description = \"${ARCH_UPPER} OpenWrt ${DEVICE} device tree blob\";
106 data = /incbin/(\"${DTB}\");
108 ${DTADDR:+load = <${DTADDR}>;}
110 compression = \"none\";
119 FDT_PROP
="fdt = \"fdt${REFERENCE_CHAR}$FDTNUM\";"
122 if [ -n "${INITRD}" ]; then
124 initrd${REFERENCE_CHAR}$INITRDNUM {
125 description = \"${ARCH_UPPER} OpenWrt ${DEVICE} initrd\";
127 data = /incbin/(\"${INITRD}\");
139 INITRD_PROP
="ramdisk=\"initrd${REFERENCE_CHAR}${INITRDNUM}\";"
143 if [ -n "${ROOTFS}" ]; then
144 dd if="${ROOTFS}" of
="${ROOTFS}.pagesync" bs
=4096 conv
=sync
146 rootfs${REFERENCE_CHAR}$ROOTFSNUM {
147 description = \"${ARCH_UPPER} OpenWrt ${DEVICE} rootfs\";
149 data = /incbin/(\"${ROOTFS}.pagesync\");
150 type = \"filesystem\";
152 compression = \"none\";
161 LOADABLES
="${LOADABLES:+$LOADABLES, }\"rootfs${REFERENCE_CHAR}${ROOTFSNUM}\""
164 # add DT overlay blobs
167 [ "$DTOVERLAY" ] && for overlay
in $DTOVERLAY ; do
168 overlay_blob
=${overlay##*:}
169 ovname
=${overlay%%:*}
171 ovsize
=$
(wc -c "$overlay_blob" |
awk '{print $1}')
172 echo "$ovname ($overlay_blob) : $ovsize" >&2
173 DTADDR
=$
(printf "0x%08x" $
(($DTADDR - $ovsize)))
174 FDTOVERLAY_NODE
="$FDTOVERLAY_NODE
177 description = \"${ARCH_UPPER} OpenWrt ${DEVICE} device tree overlay $ovname\";
179 data = /incbin/(\"${overlay_blob}\");
183 compression = \"none\";
192 OVCONFIGS
="$OVCONFIGS
195 description = \"OpenWrt ${DEVICE} overlay $ovname\";
202 # Create a default, fully populated DTS file
206 description = \"${ARCH_UPPER} OpenWrt FIT (Flattened Image Tree)\";
207 #address-cells = <1>;
210 kernel${REFERENCE_CHAR}1 {
211 description = \"${ARCH_UPPER} OpenWrt Linux-${VERSION}\";
212 data = /incbin/(\"${KERNEL}\");
216 compression = \"${COMPRESS}\";
217 load = <${LOAD_ADDR}>;
218 entry = <${ENTRY_ADDR}>;
233 default = \"${CONFIG}\";
235 description = \"OpenWrt ${DEVICE}\";
236 kernel = \"kernel${REFERENCE_CHAR}1\";
238 ${LOADABLES:+loadables = ${LOADABLES};}
246 # Write .its file to disk
247 echo "$DATA" > "${OUTPUT}"