#
# mk-images.s390
#
# Copyright (C) 2007  Red Hat, Inc.  All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

getAllS390ModuleNames() {
    s390dir="${KERNELROOT}/lib/modules/${version}/kernel/drivers/s390"
    if [ -d "${s390dir}" ]; then
        find ${s390dir} -type f -name "*.ko" | while read line ; do
            echo "$(basename ${line} .ko)"
        done | sort | uniq | tr '\n' ' '
    else
        echo "*** ERROR: ${s390dir} is missing, this tree probably won't have a working initrd.img" >&2
    fi
}

makeBootImages() {
	makeinitrd --initrdto $TOPDESTPATH/images/initrd.img \
	    --initrdsize 20000 \
	    --loaderbin loader \
	    --modules "$INITRDMODS $(getAllS390ModuleNames)"
	sz=$(ls -l $TOPDESTPATH/images/initrd.img | awk '{print $5}')
	$GENINITRDSZ $sz $TOPDESTPATH/images/initrd.size
	cp -vf $KERNELROOT/boot/${KERNELNAME}-${version} $TOPDESTPATH/images/kernel.img

	cp -v $BOOTDISKDIR/redhat.exec $TOPDESTPATH/images/redhat.exec
	cp -v $BOOTDISKDIR/generic.prm $TOPDESTPATH/images/generic.prm
	cp -v $BOOTDISKDIR/generic.ins $TOPDESTPATH/generic.ins

   $MKS390CDBOOT \
      -i $TOPDESTPATH/images/kernel.img \
      -r $TOPDESTPATH/images/initrd.img \
      -p $TOPDESTPATH/images/generic.prm \
      -o $TOPDESTPATH/images/cdboot.img

    cat << __EOT__ >> $TOPDESTPATH/.treeinfo
[images-$KERNELARCH]
kernel = images/kernel.img
initrd = images/initrd.img
initrd.size = images/initrd.size
generic.prm = images/generic.prm
generic.ins = generic.ins
cdboot.img = images/cdboot.img

__EOT__
}
