Blame SOURCES/10-devicetree.install

9067cc
#!/bin/bash
9067cc
9067cc
# set -x
9067cc
9067cc
if [[ "$(uname -m)" == arm* || "$(uname -m)" == aarch64 ]]
9067cc
then
9067cc
COMMAND="$1"
9067cc
KERNEL_VERSION="$2"
9067cc
#BOOT_DIR_ABS="$3"
9067cc
#KERNEL_IMAGE="$4"
9067cc
9067cc
[ -f /etc/u-boot.conf ] && source /etc/u-boot.conf || true
9067cc
[ -z "$FIRMWAREDT" ] || FirmwareDT=$FIRMWAREDT
9067cc
9067cc
if [[ $FirmwareDT == "True" ]]
9067cc
then
9067cc
	# if we want to use firmware DT we remove symlink to current kernel DT
9067cc
        if [ -h /boot/dtb ]; then
9067cc
            rm -f /boot/dtb
9067cc
        fi
9067cc
	exit 0
9067cc
fi
9067cc
9067cc
# Setup a /boot/dtb -> /boot/dtb-$newest_kernel_version symlink so that
9067cc
# u-boot can find the correct dtb to load.
9067cc
#
9067cc
# If invoked to 'add' a new kernel, find the newest based on `sort`ing
9067cc
# the kernel versions dtb.  If 'remove', then follow basically the same
9067cc
# procedure but exclude the version currently being removed.
9067cc
#
9067cc
# The theory of operation here is that, while newer kernels may add new
9067cc
# dtb nodes and fields, as upstreaming hw support for some particular
9067cc
# device progresses, it should never make backward incompatible changes.
9067cc
# So it should always be safe to use a newer dtb with an older kernel.
9067cc
9067cc
    list_dtb_versions() {
9067cc
        excluded_version="$1"
9067cc
        for dtbdir in /boot/dtb-*; do
9067cc
            dtbver=${dtbdir#*-}
9067cc
            if [ "$dtbver" != "$excluded_version" ]; then
9067cc
                echo $dtbver
9067cc
            fi
9067cc
        done
9067cc
    }
9067cc
9067cc
    setup_dtb_link() {
9067cc
        ver=`list_dtb_versions $1 | sort -r --sort=version | head -1`
9067cc
        if [ -h /boot/dtb ]; then
9067cc
            rm -f /boot/dtb
9067cc
        fi
9067cc
        ln -s dtb-$ver /boot/dtb
9067cc
    }
9067cc
9067cc
    ret=0
9067cc
    case "$COMMAND" in
9067cc
        add)
9067cc
            # If we're adding a kernel we want that version
9067cc
            if [ -h /boot/dtb ]; then
9067cc
                rm -f /boot/dtb
9067cc
            fi
9067cc
            ln -s dtb-$KERNEL_VERSION /boot/dtb
9067cc
            ret=$?
9067cc
            ;;
9067cc
        remove)
9067cc
            setup_dtb_link $KERNEL_VERSION
9067cc
            ret=$?
9067cc
            ;;
9067cc
    esac
9067cc
    exit $ret
9067cc
else
9067cc
    # Just exit on non ARM
9067cc
    exit 0
9067cc
fi