#!/bin/sh # Generate an its script used to build a u-boot fitImage kernel binary # that contains the kernel as well as device trees used when booting it # via mkimage or dtc. # Using mkimage will insert extra hashes that dtc will not add. kernel_arch=${ARCH} its_out=/dev/stdout dtb_dir=. show_usage() { cat <<-EOF $0 [options] -a CPU architecture -d directory where dtb files exist -h shows this message -o output its script pathname -r ramdisk image to include $0 Image dts/*.dtb | dtc -I dts -O dtb -p 1024 > Image.fit EOF } die() { exit 1 } OPTIND=1 while getopts "a:d:ho:r:" opt; do case "$opt" in a) kernel_arch=${OPTARG} ;; d) dtb_dir=${OPTARG} ;; h) show_usage exit 0 ;; o) its_out=${OPTARG} ;; r) ramdisk_path=${OPTARG} ;; esac done shift $((OPTIND-1)) if [ -z "${kernel_arch}" ]; then >&2 echo "ERROR: CPU architecture not specified" show_usage die fi image_path=${1} shift cat > "${its_out}" <<-EOF || die /dts-v1/; / { description = "Chrome OS kernel image with one or more FDT blobs"; #address-cells = <1>; images { kernel@1 { data = /incbin/("${image_path}"); type = "kernel_noload"; arch = "${kernel_arch}"; os = "linux"; compression = "none"; load = <0>; entry = <0>; }; EOF if [ -n "${ramdisk_path}" ]; then cat >> "${its_out}" <<-EOF || die ramdisk@1 { data = /incbin/("${ramdisk_path}"); type = "ramdisk"; arch = "${kernel_arch}"; os = "linux"; compression = "gzip"; load = <0>; entry = <0>; }; EOF fi iter=1 for dtb in "$@" ; do cat >> "${its_out}" <<-EOF || die fdt@${iter} { description = "$(basename ${dtb})"; data = /incbin/("${dtb_dir}/${dtb}"); type = "flat_dt"; arch = "${kernel_arch}"; compression = "none"; hash@1 { algo = "sha1"; }; }; EOF ((++iter)) done cat <<-EOF >>"${its_out}" }; configurations { default = "conf@1"; EOF for i in $(seq 1 $((iter-1))) ; do cat >> "${its_out}" <<-EOF || die conf@${i} { kernel = "kernel@1"; EOF if [ -n "${ramdisk_path}" ]; then cat >> "${its_out}" <<-EOF || die ramdisk = "ramdisk@1"; EOF fi cat >> "${its_out}" <<-EOF || die fdt = "fdt@${i}"; }; EOF done echo "};" >> "${its_out}" echo "};" >> "${its_out}"