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}\";"
95 # Conditionally create fdt information
96 if [ -n "${DTB}" ]; then
98 fdt${REFERENCE_CHAR}$FDTNUM {
99 description = \"${ARCH_UPPER} OpenWrt ${DEVICE} device tree blob\";
101 data = /incbin/(\"${DTB}\");
103 ${DTADDR:+load = <${DTADDR}>;}
105 compression = \"none\";
106 hash${REFERENCE_CHAR}1 {
109 hash${REFERENCE_CHAR}2 {
114 FDT_PROP
="fdt = \"fdt${REFERENCE_CHAR}$FDTNUM\";"
117 if [ -n "${INITRD}" ]; then
119 initrd${REFERENCE_CHAR}$INITRDNUM {
120 description = \"${ARCH_UPPER} OpenWrt ${DEVICE} initrd\";
122 data = /incbin/(\"${INITRD}\");
126 hash${REFERENCE_CHAR}1 {
129 hash${REFERENCE_CHAR}2 {
134 INITRD_PROP
="ramdisk=\"initrd${REFERENCE_CHAR}${INITRDNUM}\";"
138 if [ -n "${ROOTFS}" ]; then
139 dd if="${ROOTFS}" of
="${ROOTFS}.pagesync" bs
=4096 conv
=sync
141 rootfs${REFERENCE_CHAR}$ROOTFSNUM {
142 description = \"${ARCH_UPPER} OpenWrt ${DEVICE} rootfs\";
144 data = /incbin/(\"${ROOTFS}.pagesync\");
145 type = \"filesystem\";
147 compression = \"none\";
148 hash${REFERENCE_CHAR}1 {
151 hash${REFERENCE_CHAR}2 {
156 LOADABLES
="${LOADABLES:+$LOADABLES, }\"rootfs${REFERENCE_CHAR}${ROOTFSNUM}\""
159 # add DT overlay blobs
162 [ "$DTOVERLAY" ] && for overlay
in $DTOVERLAY ; do
163 overlay_blob
=${overlay##*:}
164 ovname
=${overlay%%:*}
166 ovsize
=$
(wc -c "$overlay_blob" |
awk '{print $1}')
167 echo "$ovname ($overlay_blob) : $ovsize" >&2
168 FDTOVERLAY_NODE
="$FDTOVERLAY_NODE
171 description = \"${ARCH_UPPER} OpenWrt ${DEVICE} device tree overlay $ovname\";
173 data = /incbin/(\"${overlay_blob}\");
176 compression = \"none\";
177 hash${REFERENCE_CHAR}1 {
180 hash${REFERENCE_CHAR}2 {
185 OVCONFIGS
="$OVCONFIGS
188 description = \"OpenWrt ${DEVICE} overlay $ovname\";
195 # Create a default, fully populated DTS file
199 description = \"${ARCH_UPPER} OpenWrt FIT (Flattened Image Tree)\";
200 #address-cells = <1>;
203 kernel${REFERENCE_CHAR}1 {
204 description = \"${ARCH_UPPER} OpenWrt Linux-${VERSION}\";
205 data = /incbin/(\"${KERNEL}\");
209 compression = \"${COMPRESS}\";
210 load = <${LOAD_ADDR}>;
211 entry = <${ENTRY_ADDR}>;
212 hash${REFERENCE_CHAR}1 {
215 hash${REFERENCE_CHAR}2 {
226 default = \"${CONFIG}\";
228 description = \"OpenWrt ${DEVICE}\";
229 kernel = \"kernel${REFERENCE_CHAR}1\";
231 ${LOADABLES:+loadables = ${LOADABLES};}
239 # Write .its file to disk
240 echo "$DATA" > "${OUTPUT}"