Blame SOURCES/extlinux.sh

Pablo Greco fc53ef
#!/bin/sh
Pablo Greco fc53ef
Pablo Greco fc53ef
# Copyright (C) 2015, 2017 Red Hat Inc.
Pablo Greco fc53ef
# Author(s): Dennis Gilmore <dennis@ausil.us>
Pablo Greco fc53ef
#            Merlin Mathesius <mmathesi@redhat.com>
Pablo Greco fc53ef
#
Pablo Greco fc53ef
# This program is free software; you can redistribute it and/or modify it
Pablo Greco fc53ef
# under the terms of the GNU General Public License as published by the
Pablo Greco fc53ef
# Free Software Foundation; either version 2 of the License, or (at your
Pablo Greco fc53ef
# option) any later version.  See http://www.gnu.org/copyleft/gpl.html for
Pablo Greco fc53ef
# the full text of the license.
Pablo Greco fc53ef
Pablo Greco fc53ef
# is the system a calxeda one
Pablo Greco fc53ef
is_calxeda() {
Pablo Greco fc53ef
    grep -Eq '^Hardware[^ ]* (Highbank|Midway)' /proc/cpuinfo
Pablo Greco fc53ef
}
Pablo Greco fc53ef
Pablo Greco fc53ef
# update /etc/sysconfig/uboot to reflect if the platform provides its own dtb and
Pablo Greco fc53ef
# we do not need to pass anything.
Pablo Greco fc53ef
update_sysconfig() {
Pablo Greco fc53ef
    sed -i -e 's/#SHIPSDTB=no/SHIPSDTB=yes/g' /etc/sysconfig/uboot
Pablo Greco fc53ef
}
Pablo Greco fc53ef
Pablo Greco fc53ef
# insert into /boot/extlinux/extlinux.conf a fdtdir line
Pablo Greco fc53ef
insert_fdtdir() {
Pablo Greco fc53ef
    # for every 'kernel' directive found, map it to an 'fdtdir' directive
Pablo Greco fc53ef
    # referencing the dtb directory and add it after the 'append' directive
Pablo Greco fc53ef
    sed -i \
Pablo Greco fc53ef
        -e '/	fdtdir/d' \
Pablo Greco fc53ef
        -e '/	kernel/{h;s/kernel/fdtdir/g;s/vmlinuz/dtb/g;x}' \
Pablo Greco fc53ef
        -e '/	append/{p;x}' \
Pablo Greco fc53ef
        /boot/extlinux/extlinux.conf
Pablo Greco fc53ef
}
Pablo Greco fc53ef
Pablo Greco fc53ef
# check if there is a rescue image and copy the dtb files if there is
Pablo Greco fc53ef
copy_rescue_dtbs() {
Pablo Greco fc53ef
    has_rescue=0
Pablo Greco fc53ef
    for target in /boot/vmlinuz-0-rescue* ; do
Pablo Greco fc53ef
        # if target exists, the glob matched a file
Pablo Greco fc53ef
        if [ -e "$target" ] ; then
Pablo Greco fc53ef
            has_rescue=1
Pablo Greco fc53ef
            dtbdest=$(echo "$target" | sed -e 's/vmlinuz/dtb/g')
Pablo Greco fc53ef
        fi
Pablo Greco fc53ef
	break
Pablo Greco fc53ef
    done
Pablo Greco fc53ef
    for target in /boot/dtb* ; do
Pablo Greco fc53ef
        # if target exists, the glob matched a file
Pablo Greco fc53ef
        if [ -e "$target" ] ; then
Pablo Greco fc53ef
            dtbsource="$target"
Pablo Greco fc53ef
        fi
Pablo Greco fc53ef
	break
Pablo Greco fc53ef
    done
Pablo Greco fc53ef
    if [ $has_rescue = 1 ] && [ ! -d "$dtbdest" ] ; then
Pablo Greco fc53ef
       mkdir "$dtbdest"
Pablo Greco fc53ef
       for dtb in $(ls "$dtbsource") ; do
Pablo Greco fc53ef
           cp "$dtbsource/$dtb" "$dtbdest/$dtb"
Pablo Greco fc53ef
       done
Pablo Greco fc53ef
    fi
Pablo Greco fc53ef
}
Pablo Greco fc53ef
Pablo Greco fc53ef
# platform ships its own dtb
Pablo Greco fc53ef
if is_calxeda
Pablo Greco fc53ef
then
Pablo Greco fc53ef
    update_sysconfig
Pablo Greco fc53ef
else
Pablo Greco fc53ef
    # need to add fdtdir to extlinux.conf
Pablo Greco fc53ef
    insert_fdtdir
Pablo Greco fc53ef
    copy_rescue_dtbs
Pablo Greco fc53ef
fi