overlay/eclass/nas-kernel.eclass

479 lines
17 KiB
Bash
Raw Normal View History

# Copyright 2004-2010 Sabayon Project
# Copyright 2010 Genlink Project
# Copyright 2010 Geos_One's Projekts
# Distributed under the terms of the GNU General Public License v2
# $
# @ECLASS-VARIABLE: K_NASPATCHES_VER
# @DESCRIPTION:
# The version of the nas patches tarball(s) to apply.
# A value of "5" would apply 2.6.12-5 to my-sources-2.6.12.ebuild
# @ECLASS-VARIABLE: K_NASKERNEL_NAME
# @DESCRIPTION:
# The kernel name used by the ebuild, it should be the ending ${PN} part
# for example, of linux-nas it is "${PN/${PN/-*}-}" (nas)
K_NASKERNEL_NAME="${K_NASKERNEL_NAME:-${PN/${PN/-*}-}}"
# @ECLASS-VARIABLE: K_NASKERNEL_URI_CONFIG
# @DESCRIPTION:
# Set this either to "no" or "yes" depending on the location of the
# kernel config files. If they are inside FILESDIR (old location)
# leave this option set to "no", otherwise set this to "yes"
K_NASKERNEL_URI_CONFIG="${K_NASKERNEL_URI_CONFIG:-no}"
# @ECLASS-VARIABLE: K_KERNEL_SOURCES_PKG
# @DESCRIPTION:
# The kernel sources package used to build this kernel binary
K_KERNEL_SOURCES_PKG="${K_KERNEL_SOURCES_PKG:-${CATEGORY}/${PN/*-}-sources-${PVR}}"
# @ECLASS-VARIABLE: K_KERNEL_PATCH_VER
# @DESCRIPTION:
# If set to "3" for example, it applies the upstream kernel
# patch corresponding to patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}.3.bz2
K_KERNEL_PATCH_VER="${K_KERNEL_PATCH_VER:-}"
# @ECLASS-VARIABLE: K_KERNEL_PATCH_HOTFIXES
# @DESCRIPTION:
# If there is the need to quickly apply patches to the kernel
# without bumping the kernel patch tarball (for eg. in case
# of just released security fixes), set this variable in your ebuild
# pointing to space separated list of patch paths.
K_KERNEL_PATCH_HOTFIXES="${K_KERNEL_PATCH_HOTFIXES:-}"
# @ECLASS-VARIABLE: K_KERNEL_DISABLE_PR_EXTRAVERSION
# @DESCRIPTION:
# Set this to "1" if you want to tell kernel-2 eclass to
# not use ${PR} in kernel EXTRAVERSION (K_NOUSEPR). Otherwise, set
# this to "0" to not set K_NOUSEPR at all.
K_KERNEL_DISABLE_PR_EXTRAVERSION="${K_KERNEL_DISABLE_PR_EXTRAVERSION:-1}"
# @ECLASS-VARIABLE: K_KERNEL_SLOT_USEPVR
# @DESCRIPTION:
# Set this to "1" if you want to use ${PVR} in SLOT variable, instead of ${PV}
# sys-kernel/linux-vserver (vserver-sources) require this. This won't work for
# firmware pkgs.
K_KERNEL_SLOT_USEPVR="${K_KERNEL_SLOT_USEPVR:-0}"
# @ECLASS-VARIABLE: K_NASKERNEL_FIRMWARE
# @DESCRIPTION:
# Set this to "1" if your ebuild is a kernel firmware package
K_FIRMWARE_PACKAGE="${K_FIRMWARE_PACKAGE:-}"
# @ECLASS-VARIABLE: K_ONLY_SOURCES
# @DESCRIPTION:
# For every kernel binary package, there is a kernel source package associated
# if your ebuild is one of them, set this to "1"
K_ONLY_SOURCES="${K_ONLY_SOURCES:-}"
# @ECLASS-VARIABLE: K_WORKAROUND_SOURCES_COLLISION
# @DESCRIPTION:
# For kernel binary packages, Workaround file collisions with kernel
# sources already providing certain files (like Makefile). Used
# by linux-openvz and linux-vserver
K_WORKAROUND_SOURCES_COLLISION="${K_WORKAROUND_SOURCES_COLLISION:-}"
# @ECLASS-VARIABLE: K_WORKAROUND_DIFFERENT_EXTRAVERSION
# @DESCRIPTION:
# Some kernel sources are shipped with their own EXTRAVERSION and
# we're kindly asked to not touch it, if this is your case, set
# this variable in order to make linux-mod_pkg_postinst happy
# (update_depmod) by feeding it with valid KV_FULL, that will be
# calculated using EXTRAVERSION in Makefile.
K_WORKAROUND_DIFFERENT_EXTRAVERSION="${K_WORKAROUND_DIFFERENT_EXTRAVERSION:-}"
KERN_INITRAMFS_SEARCH_NAME="${KERN_INITRAMFS_SEARCH_NAME:-initramfs-genkernel*${K_NASKERNEL_NAME}}"
# Disable deblobbing feature
K_DEBLOB_AVAILABLE=0
inherit eutils kernel-2 mount-boot linux-mod
# from kernel-2 eclass
detect_version
detect_arch
DESCRIPTION="NAS Linux kernel functions and phases"
## kernel-2 eclass settings
if [ -n "${K_NASPATCHES_VER}" ]; then
UNIPATCH_STRICTORDER="yes"
K_NASPATCHES_PKG="nas-patches-${PV}-${K_NASPATCHES_VER}.tar.bz2"
UNIPATCH_LIST="${DISTFILES}/${K_NASPATCHES_PKG}"
SRC_URI="${KERNEL_URI}
http://ftp.disconnected-by-peer.at/genlink/${CATEGORY}/linux-nas-patches/${K_NASPATCHES_PKG}"
else
SRC_URI="${KERNEL_URI}"
fi
if [ -n "${K_KERNEL_PATCH_VER}" ]; then
K_PATCH_NAME="patch-${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}.${K_KERNEL_PATCH_VER}.bz2"
SRC_URI="${SRC_URI}
mirror://kernel/linux/kernel/v${KV_MAJOR}.${KV_MINOR}/${K_PATCH_NAME}"
UNIPATCH_LIST="${DISTDIR}/${K_PATCH_NAME}
${UNIPATCH_LIST}"
fi
if [ -n "${K_KERNEL_PATCH_HOTFIXES}" ]; then
UNIPATCH_LIST="${K_KERNEL_PATCH_HOTFIXES} ${UNIPATCH_LIST}"
fi
# replace "linux" with K_NASKERNEL_NAME, usually replaces
# "linux" with "nas" or "server" or "openvz"
KV_FULL="${KV_FULL/${PN/-*}/${K_NASKERNEL_NAME}}"
EXTRAVERSION="${EXTRAVERSION/${PN/-*}/${K_NASKERNEL_NAME}}"
# drop -rX if exists
[[ -n "${PR//r0}" ]] && [[ "${K_KERNEL_DISABLE_PR_EXTRAVERSION}" = "1" ]] && \
EXTRAVERSION="${EXTRAVERSION/-r*}" && KV_FULL="${KV_FULL/-r*}" && \
KV="${KV/-r*}"
KV_OUT_DIR="/usr/src/linux-${KV_FULL}"
S="${WORKDIR}/linux-${KV_FULL}"
if [ -n "${K_FIRMWARE_PACKAGE}" ]; then
SLOT="0"
elif [ "${K_KERNEL_SLOT_USEPVR}" = "1" ]; then
SLOT="${PVR}"
else
SLOT="${PV}"
fi
# provide extra virtual pkg
if [ -z "${K_FIRMWARE_PACKAGE}" ]; then
PROVIDE="${PROVIDE} virtual/linux-binary"
fi
HOMEPAGE="http://linamh.disconnected-by-peer.at/wiki/Genlink"
if [ "${K_NASKERNEL_URI_CONFIG}" = "yes" ]; then
K_NASKERNEL_CONFIG_FILE="${K_NASKERNEL_CONFIG_FILE:-${K_NASKERNEL_NAME}-${PVR}-__ARCH__.config}"
SRC_URI="${SRC_URI}
arm? ( http://ftp.disconnected-by-peer.at/genlink/${CATEGORY}/linux-nas-patches/config/${K_NASKERNEL_CONFIG_FILE/__ARCH__/arm} )"
use arm && K_NASKERNEL_CONFIG_FILE=${K_NASKERNEL_CONFIG_FILE/__ARCH__/arm}
else
use arm && K_NASKERNEL_CONFIG_FILE="${K_NASKERNEL_CONFIG_FILE:-${K_NASKERNEL_NAME}-${PVR}-arm.config}"
fi
if [ -n "${K_ONLY_SOURCES}" ] || [ -n "${K_FIRMWARE_PACKAGE}" ]; then
IUSE="${IUSE}"
DEPEND="sys-apps/sed"
RDEPEND="${RDEPEND}"
else
IUSE="dmraid"
DEPEND="sys-apps/sed
app-arch/xz-utils
sys-kernel/genkernel
sys-block/devio
dev-embedded/u-boot-tools"
# rdepend app-admin/nas-eselct
RDEPEND="sys-apps/sed
>=sys-kernel/linux-firmwares-${PV}"
fi
nas-kernel_pkg_setup() {
# do not run linux-mod-pkg_setup
if [ -n "${K_FIRMWARE_PACKAGE}" ]; then
einfo "Preparing to build kernel firmwares"
else
einfo "Preparing to build the kernel and its modules"
fi
}
nas-kernel_src_compile() {
if [ -n "${K_FIRMWARE_PACKAGE}" ]; then
_firmwares_src_compile
elif [ -n "${K_ONLY_SOURCES}" ]; then
kernel-2_src_compile
else
_kernel_src_compile
fi
}
_firmwares_src_compile() {
einfo "Starting to compile firmwares..."
_kernel_copy_config "${S}/.config"
cd "${S}" || die "cannot find source dir"
export LDFLAGS=""
OLDARCH="${ARCH}"
unset ARCH
emake firmware || die "cannot compile firmwares"
ARCH="${OLDARCH}"
}
_kernel_copy_config() {
if [ "${K_NASKERNEL_URI_CONFIG}" = "no" ]; then
cp "${FILESDIR}/${PF/-r0/}-${ARCH}.config" "${1}" || die "cannot copy kernel config"
else
cp "${DISTDIR}/${K_NASKERNEL_CONFIG_FILE}" "${1}" || die "cannot copy kernel config"
fi
}
_kernel_src_compile() {
# disable sandbox
export SANDBOX_ON=0
export LDFLAGS=""
# do some cleanup
rm -rf "${WORKDIR}"/lib
rm -rf "${WORKDIR}"/cache
rm -rf "${S}"/temp
# creating workdirs
mkdir -p "${WORKDIR}"/lib/lib/firmware
mkdir "${WORKDIR}"/cache
mkdir "${S}"/temp
mkdir -p "${WORKDIR}"/boot
einfo "Starting to compile kernel..."
_kernel_copy_config "${WORKDIR}"/config
OLDARCH="${ARCH}"
unset ARCH
cd "${S}"
GKARGS="--disklabel"
use dmraid && GKARGS="${GKARGS} --dmraid"
export DEFAULT_KERNEL_SOURCE="${S}"
export CMD_KERNEL_DIR="${S}"
for opt in ${MAKEOPTS}; do
if [ "${opt:0:2}" = "-j" ]; then
mkopts="${opt}"
break
fi
done
[ -z "${mkopts}" ] && mkopts="-j2"
DEFAULT_KERNEL_SOURCE="${S}" CMD_KERNEL_DIR="${S}" genkernel ${GKARGS} \
--kerneldir="${S}" \
--arch-override="${OLDARCH}" \
--kernel-config="${WORKDIR}"/config \
--cachedir="${WORKDIR}"/cache \
--makeopts="${mkopts}" \
--tempdir="${S}"/temp \
--logfile="${WORKDIR}"/genkernel.log \
--bootdir="${WORKDIR}"/boot \
--mountboot \
--lvm \
--luks \
--iscsi \
--module-prefix="${WORKDIR}"/lib \
all || die "genkernel failed"
ARCH=${OLDARCH}
if [ "${K_NASKERNEL_NAME}" = "buffalo_ls_pro_live" ]; then
devio > foo 'wl 0xe3a01c06,4' 'wl 0xe3811031,4' # Linkstation Pro/Live (2.6.26)
cat foo "${WORKDIR}"/boot/kernel-genkernel-${ARCH}-${KV_FULL} > zImage.new
mkimage -A arm -O linux -T kernel -C none -a 0x00008000 -e 0x00008000 -n uImage-genkernel-${ARCH}-${KV_FULL} \
-d zImage.new "${WORKDIR}"/boot/uImage-genkernel-${ARCH}-${KV_FULL}.buffalo
rm foo zImage.new
mkimage -A arm -O linux -T ramdisk -C gzip -a 0x00000000 -e 0x00000000 -n initrd-genkernel-${ARCH}-${KV_FULL} \
-d "${WORKDIR}"/boot/initramfs-genkernel-${ARCH}-${KV_FULL} "${WORKDIR}"/boot/initrd-genkernel-${ARCH}-${KV_FULL}.buffalo
rm "${WORKDIR}"/boot/kernel-genkernel-${ARCH}-${KV_FULL} "${WORKDIR}"/boot/initramfs-genkernel-${ARCH}-${KV_FULL}
fi
if [ "${K_NASKERNEL_NAME}" = "buffalo_ls_pro_duo" ]; then
devio > foo 'wl 0xe3a01c07,4' 'wl 0xe3811027,4' # Linkstation Pro Duo (2.6.30)
cat foo "${WORKDIR}"/boot/kernel-genkernel-${ARCH}-${KV_FULL} > zImage.new
mkimage -A arm -O linux -T kernel -C none -a 0x00008000 -e 0x00008000 -n uImage-${KV_FULL} \
-d zImage.new "${WORKDIR}"/boot/uImage-genkernel-${ARCH}-${KV_FULL}.buffalo
rm foo zImage.new
mkimage -A arm -O linux -T ramdisk -C gzip -a 0x00000000 -e 0x00000000 -n initrd-${KV_FULL} \
-d "${WORKDIR}"/boot/initramfs-genkernel-${ARCH}-${KV_FULL} "${WORKDIR}"/boot/initrd-genkernel-${ARCH}-${KV_FULL}.buffalo
rm "${WORKDIR}"/boot/kernel-genkernel-${ARCH}-${KV_FULL} "${WORKDIR}"/boot/initramfs-genkernel-${ARCH}-${KV_FULL}
fi
if [ "${K_NASKERNEL_NAME}" = "buffalo_ls_xhl" ]; then
devio > foo 'wl 0xe3a01c0a,4' 'wl 0xe3811067,4' # Linkstation XHL/CHLv2 (2.6.30)
cat foo "${WORKDIR}"/boot/kernel-genkernel-${ARCH}-${KV_FULL} > zImage.new
mkimage -A arm -O linux -T kernel -C none -a 0x00008000 -e 0x00008000 -n uImage-${KV_FULL} \
-d zImage.new "${WORKDIR}"/boot/uImage-genkernel-${ARCH}-${KV_FULL}.buffalo
rm foo zImage.new
mkimage -A arm -O linux -T ramdisk -C gzip -a 0x00000000 -e 0x00000000 -n initrd-${KV_FULL} \
-d "${WORKDIR}"/boot/initramfs-genkernel-${ARCH}-${KV_FULL} "${WORKDIR}"/boot/initrd-genkernel-${ARCH}-${KV_FULL}.buffalo
rm "${WORKDIR}"/boot/kernel-genkernel-${ARCH}-${KV_FULL} "${WORKDIR}"/boot/initramfs-genkernel-${ARCH}-${KV_FULL}
fi
if [ "${K_NASKERNEL_NAME}" = "buffalo_ls_chl" ]; then
devio > foo 'wl 0xe3a01c0B,4' 'wl 0xe3811061,4' # Linkstation Live V3 (2.6.34)
cat foo "${WORKDIR}"/boot/kernel-genkernel-${ARCH}-${KV_FULL} > zImage.new
mkimage -A arm -O linux -T kernel -C none -a 0x00008000 -e 0x00008000 -n uImage-${KV_FULL} \
-d zImage.new "${WORKDIR}"/boot/uImage-genkernel-${ARCH}-${KV_FULL}.buffalo
rm foo zImage.new
mkimage -A arm -O linux -T ramdisk -C gzip -a 0x00000000 -e 0x00000000 -n initrd-${KV_FULL} \
-d "${WORKDIR}"/boot/initramfs-genkernel-${ARCH}-${KV_FULL} "${WORKDIR}"/boot/initrd-genkernel-${ARCH}-${KV_FULL}.buffalo
rm "${WORKDIR}"/boot/kernel-genkernel-${ARCH}-${KV_FULL} "${WORKDIR}"/boot/initramfs-genkernel-${ARCH}-${KV_FULL}
fi
if [ "${K_NASKERNEL_NAME}" = "buffalo_ls_wxl" ]; then
devio > foo 'wl 0xe3a01c0c,4' 'wl 0xe381108a,4' # Linkstation WXL (2.6.30)
cat foo "${WORKDIR}"/boot/kernel-genkernel-${ARCH}-${KV_FULL} > zImage.new
mkimage -A arm -O linux -T kernel -C none -a 0x00008000 -e 0x00008000 -n uImage-${KV_FULL} \
-d zImage.new "${WORKDIR}"/boot/uImage-genkernel-${ARCH}-${KV_FULL}.buffalo
rm foo zImage.new
mkimage -A arm -O linux -T ramdisk -C gzip -a 0x00000000 -e 0x00000000 -n initrd-${KV_FULL} \
-d "${WORKDIR}"/boot/initramfs-genkernel-${ARCH}-${KV_FULL} "${WORKDIR}"/boot/initrd-genkernel-${ARCH}-${KV_FULL}.buffalo
rm "${WORKDIR}"/boot/kernel-genkernel-${ARCH}-${KV_FULL} "${WORKDIR}"/boot/initramfs-genkernel-${ARCH}-${KV_FULL}
fi
}
nas-kernel_src_install() {
if [ -n "${K_FIRMWARE_PACKAGE}" ]; then
_firmwares_src_install
elif [ -n "${K_ONLY_SOURCES}" ]; then
_kernel_sources_src_install
else
_kernel_src_install
fi
}
_firmwares_src_install() {
dodir /lib/firmware
keepdir /lib/firmware
( cd "${S}" && emake INSTALL_FW_PATH="${D}/lib/firmware" firmware_install ) || die "cannot install firmwares"
}
_kernel_sources_src_install() {
local version_h_name="usr/src/linux-${KV_FULL}/include/linux"
local version_h="${ROOT}${version_h_name}"
if [ -f "${version_h}" ]; then
einfo "Discarding previously installed version.h to avoid collisions"
addwrite "/${version_h_name}"
rm -f "${version_h}"
fi
kernel-2_src_install
cd "${D}/usr/src/linux-${KV_FULL}"
local oldarch="${ARCH}"
cp "${DISTDIR}/${K_NASKERNEL_CONFIG_FILE}" .config || die "cannot copy kernel config"
unset ARCH
if ! use sources_standalone; then
make modules_prepare || die "failed to run modules_prepare"
rm .config || die "cannot remove .config"
rm Makefile || die "cannot remove Makefile"
rm include/linux/version.h || die "cannot remove include/linux/version.h"
fi
ARCH="${oldarch}"
}
_kernel_src_install() {
dodir "${KV_OUT_DIR}"
insinto "${KV_OUT_DIR}"
if [ "${K_NASKERNEL_URI_CONFIG}" = "no" ]; then
cp "${FILESDIR}/${PF/-r0/}-${OLDARCH}.config" .config || die "cannot copy kernel config"
else
cp "${DISTDIR}/${K_NASKERNEL_CONFIG_FILE}" .config || die "cannot copy kernel config"
fi
doins ".config" || die "cannot copy kernel config"
doins Makefile || die "cannot copy Makefile"
doins Module.symvers || die "cannot copy Module.symvers"
doins System.map || die "cannot copy System.map"
# NOTE: this is a workaround caused by linux-info.eclass not
# being ported to EAPI=2 yet
local version_h_name="usr/src/linux-${KV_FULL}/include/linux"
local version_h="${ROOT}${version_h_name}/version.h"
if [ -f "${version_h}" ]; then
einfo "Discarding previously installed version.h to avoid collisions"
addwrite "${version_h}"
rm -f "${version_h}"
fi
# Include include/linux/version.h to make Portage happy
dodir "${KV_OUT_DIR}/include/linux"
insinto "${KV_OUT_DIR}/include/linux"
doins "${S}/include/linux/version.h" || die "cannot copy version.h"
insinto "/boot"
doins "${WORKDIR}"/boot/*
cp -Rp "${WORKDIR}"/lib/* "${D}/"
# This doesn't always work because KV_FULL (when K_NOSETEXTRAVERSION=1) doesn't
# reflect the real value used in Makefile
#dosym "../../..${KV_OUT_DIR}" "/lib/modules/${KV_FULL}/source" || die "cannot install source symlink"
#dosym "../../..${KV_OUT_DIR}" "/lib/modules/${KV_FULL}/build" || die "cannot install build symlink"
cd "${D}"/lib/modules/* || die "cannot enter /lib/modules directory, more than one element?"
# cleanup previous
rm -f build source || die
# create sane symlinks
ln -sf "../../..${KV_OUT_DIR}" source || die "cannot create source symlink"
ln -sf "../../..${KV_OUT_DIR}" build || die "cannot create build symlink"
cd "${S}"
# drop ${D}/lib/firmware, virtual/linux-firmwares provides it
rm -rf "${D}/lib/firmware"
if [ -n "${K_WORKAROUND_SOURCES_COLLISION}" ]; then
# Fixing up Makefile collision if already installed by
# openvz-sources
einfo "Workarounding source package collisions"
make_file="usr/src/linux-${KV_FULL}/Makefile"
einfo "Makefile: ${make_file}"
if [ -f "${ROOT}/${make_file}" ]; then
elog "Removing ${D}/${make_file}"
rm -f "${D}/${make_file}"
fi
fi
}
_get_real_extraversion() {
make_file="${ROOT}${KV_OUT_DIR}/Makefile"
local extraver=$(grep -r "^EXTRAVERSION" "${make_file}" | cut -d "=" -f 2)
local trimmed=${extraver%% }
echo ${trimmed## }
}
nas-kernel_pkg_preinst() {
if [ -z "${K_ONLY_SOURCES}" ] && [ -z "${K_FIRMWARE_PACKAGE}" ]; then
mount-boot_pkg_preinst
linux-mod_pkg_preinst
UPDATE_MODULEDB=false
fi
}
nas-kernel_pkg_postinst() {
if [ -z "${K_ONLY_SOURCES}" ] && [ -z "${K_FIRMWARE_PACKAGE}" ]; then
fstab_file="${ROOT}etc/fstab"
einfo "Removing extents option for ext4 drives from ${fstab_file}"
# Remove "extents" from /etc/fstab
if [ -f "${fstab_file}" ]; then
sed -i '/ext4/ s/extents//g' "${fstab_file}"
fi
kernel-2_pkg_postinst
if [ -n "${K_WORKAROUND_DIFFERENT_EXTRAVERSION}" ]; then
UPDATE_DEPMOD="false"
local depmod_r="${KV_MAJOR}.${KV_MINOR}.${KV_PATCH}$(_get_real_extraversion)"
einfo "Updating (overridden) modules dependencies using ${depmod_r}"
[[ -r "${KV_OUT_DIR}"/System.map ]] && \
depmod -ae -F "${KV_OUT_DIR}"/System.map -b "${ROOT}" \
-r "${depmod_r}"
fi
linux-mod_pkg_postinst
elog "Please report kernel bugs at:"
elog "http://linamh.disconnected-by-peer.at/report"
elog "using the Ticket Component \"Genlink\""
elog "The source code of this kernel is located at"
elog "=${K_KERNEL_SOURCES_PKG}."
elog "Genlink Linux recommends that portage users install"
elog "${K_KERNEL_SOURCES_PKG} if you want"
elog "to build any packages that install kernel modules"
elog "(such as sim_buffalo, etc...)."
else
kernel-2_pkg_postinst
fi
}
nas-kernel_pkg_prerm() {
if [ -z "${K_ONLY_SOURCES}" ] && [ -z "${K_FIRMWARE_PACKAGE}" ]; then
mount-boot_pkg_prerm
fi
}
nas-kernel_pkg_postrm() {
if [ -z "${K_ONLY_SOURCES}" ] && [ -z "${K_FIRMWARE_PACKAGE}" ]; then
linux-mod_pkg_postrm
fi
}
# export all the available functions here
EXPORT_FUNCTIONS pkg_setup src_compile src_install pkg_preinst pkg_postinst pkg_prerm pkg_postrm