--- genkernel-3.4.5/gen_cmdline.sh +++ genkernel-3.4.5/gen_cmdline.sh @@ -77,6 +77,7 @@ longusage() { echo " --lvm2 Include LVM2 support" # echo " --unionfs Include UNIONFS support" echo " --dmraid Include DMRAID support" + echo " --suspend Include userspace suspend/resume (uswsusp) support" echo " --slowusb Enables extra pauses for slow USB CD boots" echo " --bootloader=grub Add new kernel to GRUB configuration" echo " --linuxrc= Specifies a user created linuxrc" @@ -226,6 +227,17 @@ parse_cmdline() { CMD_LVM2=1 print_info 2 "CMD_LVM2: $CMD_LVM2" ;; + --suspend) + if [ ! -e /etc/suspend.conf ] + then + echo 'Error: --suspend requires sys-power/suspend to be installed' + echo ' on the host system; try "emerge sys-power/suspend".' + echo ' Once installed, configure the resume settings in /etc/suspend.conf' + exit 1 + fi + CMD_SUSPEND=1 + print_info 2 "CMD_SUSPEND: $CMD_SUSPEND" + ;; --no-busybox) CMD_NO_BUSYBOX=1 print_info 2 "CMD_NO_BUSYBOX: $CMD_NO_BUSYBOX" --- genkernel-3.4.5/gen_compile.sh +++ genkernel-3.4.5/gen_compile.sh @@ -187,8 +187,10 @@ compile_generic() { local RET [ "$#" -lt '2' ] && gen_die 'compile_generic(): improper usage!' + local target=${1} + local argstype=${2} - if [ "${2}" = 'kernel' ] || [ "${2}" = 'runtask' ] + if [ "${argstype}" = 'kernel' ] || [ "${argstype}" = 'runtask' ] then export_kernel_args MAKE=${KERNEL_MAKE} @@ -197,42 +199,43 @@ compile_generic() { export_utils_args MAKE=${UTILS_MAKE} fi - case "$2" in + case "${argstype}" in kernel) ARGS="`compile_kernel_args`" ;; utils) ARGS="`compile_utils_args`" ;; *) ARGS="" ;; # includes runtask esac - + shift 2 + # the eval usage is needed in the next set of code # as ARGS can contain spaces and quotes, eg: # ARGS='CC="ccache gcc"' - if [ "${2}" == 'runtask' ] + if [ "${argstype}" == 'runtask' ] then - print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS/-j?/j1} ${ARGS} ${1}" 1 0 1 - eval ${MAKE} -s ${MAKEOPTS/-j?/-j1} "${ARGS}" ${1} + print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS/-j?/j1} ${ARGS} ${target} $*" 1 0 1 + eval ${MAKE} -s ${MAKEOPTS/-j?/-j1} "${ARGS}" ${target} $* RET=$? elif [ "${DEBUGLEVEL}" -gt "1" ] then # Output to stdout and debugfile - print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS} ${ARGS} ${1}" 1 0 1 - eval ${MAKE} ${MAKEOPTS} ${ARGS} ${1} 2>&1 | tee -a ${DEBUGFILE} + print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS} ${ARGS} ${target} $*" 1 0 1 + eval ${MAKE} ${MAKEOPTS} ${ARGS} ${target} $* 2>&1 | tee -a ${DEBUGFILE} RET=${PIPESTATUS[0]} else # Output to debugfile only - print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS} ${ARGS} ${1}" 1 0 1 - eval ${MAKE} ${MAKEOPTS} ${ARGS} ${1} >> ${DEBUGFILE} 2>&1 + print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS} ${ARGS} ${1} $*" 1 0 1 + eval ${MAKE} ${MAKEOPTS} ${ARGS} ${target} $* >> ${DEBUGFILE} 2>&1 RET=$? fi [ "${RET}" -ne '0' ] && - gen_die "Failed to compile the \"${1}\" target..." + gen_die "Failed to compile the \"${target}\" target..." unset MAKE unset ARGS - if [ "${2}" = 'kernel' ] + if [ "${argstype}" = 'kernel' ] then unset_kernel_args - elif [ "${2}" = 'utils' ] + elif [ "${argstype}" = 'utils' ] then unset_utils_args fi @@ -529,6 +532,39 @@ compile_dmraid() { fi } +compile_suspend() { + [ -f "${SUSPEND_BINCACHE}" ] && return + [ -f "${SUSPEND_SRCTAR}" ] || + gen_die "Could not find SUSPEND source tarball: ${SUSPEND_SRCTAR}! Please place it there, or place another version, changing /etc/genkernel.conf as necessary!" + cd ${TEMP} + rm -rf ${SUSPEND_DIR} > /dev/null + /bin/tar -zxpf ${SUSPEND_SRCTAR} || + gen_die 'Could not extract SUSPEND source tarball!' + [ -d "${SUSPEND_DIR}" ] || + gen_die "SUSPEND directory ${DMRAID_DIR} is invalid!" + + cd "${SUSPEND_DIR}" + if [ -f "${GK_SHARE}/pkg/suspend-0.5-Makefile.patch" ] + then + patch -p1 -i \ + ${GK_SHARE}/pkg/suspend-0.5-Makefile.patch \ + || gen_die "Failed patching suspend" + fi + + print_info 1 'suspend: >> Compiling...' + compile_generic '' utils CC_FLAGS= LD_FLAGS= + + print_info 1 ' >> Copying to bincache...' + mkdir -p "${TEMP}/bincache/sbin" + cp -f resume "${TEMP}/bincache/sbin" || + gen_die 'Could not copy resume binary' + cd "${TEMP}/bincache" + /bin/tar -cjf "${SUSPEND_BINCACHE}" * || + gen_die 'Could not create suspend binary cache' + cd "${TEMP}" + rm -rf bincache suspend-0.5 +} + compile_modutils() { # I've disabled dietlibc support for the time being since the # version we use misses a few needed system calls. --- genkernel-3.4.5/gen_configkernel.sh +++ genkernel-3.4.5/gen_configkernel.sh @@ -120,4 +120,11 @@ config_kernel() { then sed -i ${KERNEL_DIR}/.config -e 's/#\? \?CONFIG_FB_SPLASH is.*/CONFIG_FB_SPLASH=y/g' fi + + # This check isn't complete: SOFTWARE_SUSPEND has extra deps on some systems such as CPU hotplug + if isTrue ${CMD_SUSPEND} + then + sed -i ${KERNEL_DIR}/.config -e 's/#\? \?CONFIG_SOFTWARE_SUSPEND is.*/CONFIG_SOFTWARE_SUSPEND=y/g' + fi + } --- genkernel-3.4.5/gen_determineargs.sh +++ genkernel-3.4.5/gen_determineargs.sh @@ -212,6 +212,7 @@ determine_real_args() { UNIONFS_BINCACHE=`cache_replace "${UNIONFS_BINCACHE}"` UNIONFS_MODULES_BINCACHE=`cache_replace "${UNIONFS_MODULES_BINCACHE}"` BLKID_BINCACHE=`cache_replace "${BLKID_BINCACHE}"` + SUSPEND_BINCACHE=`cache_replace "${SUSPEND_BINCACHE}"` DEFAULT_KERNEL_CONFIG=`arch_replace "${DEFAULT_KERNEL_CONFIG}"` BUSYBOX_CONFIG=`arch_replace "${BUSYBOX_CONFIG}"` @@ -230,6 +231,7 @@ determine_real_args() { UNIONFS_BINCACHE=`arch_replace "${UNIONFS_BINCACHE}"` UNIONFS_MODULES_BINCACHE=`arch_replace "${UNIONFS_MODULES_BINCACHE}"` BLKID_BINCACHE=`arch_replace "${BLKID_BINCACHE}"` + SUSPEND_BINCACHE=`arch_replace "${SUSPEND_BINCACHE}"` if [ "${CMD_BOOTSPLASH}" != '' ] then @@ -423,6 +425,13 @@ determine_real_args() { else LVM2=0 fi + + if isTrue "${CMD_SUSPEND}" + then + SUSPEND=1 + else + SUSPEND=0 + fi if isTrue "${CMD_EVMS2}" then --- genkernel-3.4.5/generic/initrd.scripts +++ genkernel-3.4.5/generic/initrd.scripts @@ -743,6 +743,18 @@ setup_unionfs() { fi } +suspend_resume() { + [ -x /sbin/resume ] || return 0 + /sbin/resume + local ret=$? + + if [ "${ret}" -eq 0 ]; then + exit 0 + fi + + return 0 +} + suspend2_resume() { if [ -d /proc/suspend2 ] || [ -d /sys/power/suspend2 ]; then local splash_theme --- genkernel-3.4.5/generic/linuxrc +++ genkernel-3.4.5/generic/linuxrc @@ -250,6 +250,7 @@ fi # Run debug shell if requested rundebugshell +suspend_resume suspend2_resume if [ "${CDROOT}" -eq '1' ] --- genkernel-3.4.5/genkernel.conf +++ genkernel-3.4.5/genkernel.conf @@ -142,3 +142,9 @@ E2FSPROGS_VER="VERSION_E2FSPROGS" E2FSPROGS_DIR="e2fsprogs-${E2FSPROGS_VER}" E2FSPROGS_SRCTAR="${GK_SHARE}/pkg/e2fsprogs-${E2FSPROGS_VER}.tar.gz" BLKID_BINCACHE="%%CACHE%%/blkid-${E2FSPROGS_VER}-%%ARCH%%.bz2" + +SUSPEND_VER="VERSION_SUSPEND" +SUSPEND_DIR="suspend-${SUSPEND_VER}" +SUSPEND_SRCTAR="${GK_SHARE}/pkg/suspend-${SUSPEND_VER}.tar.gz" +SUSPEND_BINCACHE="%%CACHE%%/suspend-${SUSPEND_VER}-%%ARCH%%.tar.bz2" + --- genkernel-3.4.5/gen_initramfs.sh +++ genkernel-3.4.5/gen_initramfs.sh @@ -173,6 +173,23 @@ create_unionfs_tools_cpio(){ fi } +create_suspend_cpio(){ + if [ -d "${TEMP}/initramfs-suspend-temp" ]; + then + rm -r "${TEMP}/initramfs-suspend-temp/" + fi + print_info 1 'SUSPEND: Adding support (compiling binaries)...' + compile_suspend + mkdir -p "${TEMP}/initramfs-suspend-temp/" + /bin/tar -jxpf "${SUSPEND_BINCACHE}" -C "${TEMP}/initramfs-suspend-temp" || + gen_die "Could not extract suspend binary cache!" + mkdir -p "${TEMP}/initramfs-suspend-temp/etc" + cp -f /etc/suspend.conf "${TEMP}/initramfs-suspend-temp/etc" || + gen_die 'Could not copy /etc/suspend.conf' + cd "${TEMP}/initramfs-suspend-temp/" + find . -print | cpio --quiet -o -H newc | gzip -9 > ${CACHE_CPIO_DIR}/initramfs-suspend-${SUSPEND_VER}.cpio.gz +} + create_dmraid_cpio(){ # DMRAID if [ "${DMRAID}" = '1' ] @@ -510,6 +527,10 @@ merge_initramfs_cpio_archives(){ then MERGE_LIST="${MERGE_LIST} initramfs-unionfs-${UNIONFS_VER}-modules-${KV}.cpio.gz" fi + if [ "${SUSPEND}" -eq '1' -a -e "${CACHE_CPIO_DIR}/initramfs-suspend-${SUSPEND_VER}.cpio.gz" ] + then + MERGE_LIST="${MERGE_LIST} initramfs-suspend-${SUSPEND_VER}.cpio.gz" + fi if [ "${EVMS2}" -eq '1' -a -e "${CACHE_CPIO_DIR}/initramfs-evms2.cpio.gz" ] then MERGE_LIST="${MERGE_LIST} initramfs-evms2.cpio.gz" @@ -616,6 +637,12 @@ create_initramfs() { print_info 1 " >> Creating unionfs tools cpio archive..." create_unionfs_tools_cpio fi + + if [ "${SUSPEND}" -eq '1' ] + then + print_info 1 " >> Creating suspend cpio archive..." + create_suspend_cpio + fi if [ "${LVM2}" -eq '1' ] then --- genkernel-3.4.5/genkernel.8 +++ genkernel-3.4.5/genkernel.8 @@ -186,6 +186,13 @@ Add in LVM2 support from static binaries or compile static LVM2 binaries if static ones do not exist. .RE .TP +\fB\-\-suspend\fR +.RS +Add support for userspace suspend/resume (uswsusp). This option requires +Linux 2.6.17 or newer, \fBsys-power/suspend\fR installed on the host system, +and resume configured in \fB/etc/suspend.conf\fR. +.RE +.TP \fB\-\-no-udev\fR Force devfs on 2.6 series kernels. Not recommended or supported. .TP