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