Blame SOURCES/10-devicetree.install

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