From 6bd24fcfb302a9a03d3e51ca9b4143bd0058631c Mon Sep 17 00:00:00 2001 From: "John P. Davis" Date: Tue, 11 Jan 2005 15:22:41 +0000 Subject: [PATCH] netboot path from gmsoft@gentoo.org git-svn-id: svn+ssh://svn.gentoo.org/var/svnroot/catalyst/trunk@516 d1e1f19c-881f-0410-ab34-b69fee027534 --- ChangeLog | 9 ++- targets/netboot/netboot-busybox.sh | 16 +++- targets/netboot/netboot-combine.sh | 6 +- targets/netboot/netboot-image.sh | 117 +++++++++++++++++------------ targets/netboot/netboot-kernel.sh | 26 ++++--- targets/netboot/netboot.sh | 6 +- 6 files changed, 112 insertions(+), 68 deletions(-) diff --git a/ChangeLog b/ChangeLog index ef9e30b4..6a5ee64b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,13 @@ # ChangeLog for gentoo/src/catalyst # Copyright 2002-2005 Gentoo Foundation; Distributed under the GPL v2 -# $Header: /var/cvsroot/gentoo/src/catalyst/ChangeLog,v 1.143 2005/01/11 14:10:18 wolf31o2 Exp $ +# $Header: /var/cvsroot/gentoo/src/catalyst/ChangeLog,v 1.144 2005/01/11 15:22:41 zhen Exp $ + + 11 Jan 2005; John Davis + targets/netboot/netboot-busybox.sh, targets/netboot/netboot-combine.sh, + targets/netboot/netboot-image.sh, targets/netboot/netboot-kernel.sh, + targets/netboot/netboot.sh: + netboot path from gmsoft@gentoo.org. The patch addresses many bugs and adds + some feature enhancements. 11 Jan 2005; Chris Gianelloni catalyst, targets/embedded/embedded-chroot.sh, targets/grp/grp-chroot.sh, diff --git a/targets/netboot/netboot-busybox.sh b/targets/netboot/netboot-busybox.sh index 6d5fafdf..17168f18 100644 --- a/targets/netboot/netboot-busybox.sh +++ b/targets/netboot/netboot-busybox.sh @@ -1,7 +1,7 @@ #!/bin/bash # Copyright 1999-2004 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo/src/catalyst/targets/netboot/Attic/netboot-busybox.sh,v 1.3 2004/10/11 14:19:30 zhen Exp $ +# $Header: /var/cvsroot/gentoo/src/catalyst/targets/netboot/Attic/netboot-busybox.sh,v 1.4 2005/01/11 15:22:41 zhen Exp $ /usr/sbin/env-update source /etc/profile @@ -14,5 +14,15 @@ export CONFIG_PROTECT="-*" export USE_ORDER="env:conf:defaults" # Use the catalyst config -export USE="savedconfig netboot" -ROOT=${IMAGE_PATH} emerge --nodeps ${clst_myemergeopts} busybox || exit 1 +export USE="netboot make-busybox-symlinks" + +if [ ! -z "${1}" ] +then + export USE="${USE} savedconfig" + # Do not use package for busybox since the config can change + ROOT=${IMAGE_PATH} emerge --nodeps busybox || exit 1 +else + ROOT=${IMAGE_PATH} emerge --nodeps ${clst_myemergeopts} busybox || exit 1 + +fi + diff --git a/targets/netboot/netboot-combine.sh b/targets/netboot/netboot-combine.sh index ef761319..bf7f6599 100644 --- a/targets/netboot/netboot-combine.sh +++ b/targets/netboot/netboot-combine.sh @@ -1,7 +1,7 @@ #!/bin/bash # Copyright 1999-2004 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo/src/catalyst/targets/netboot/netboot-combine.sh,v 1.1 2004/10/11 14:28:27 zhen Exp $ +# $Header: /var/cvsroot/gentoo/src/catalyst/targets/netboot/netboot-combine.sh,v 1.2 2005/01/11 15:22:41 zhen Exp $ /usr/sbin/env-update source /etc/profile @@ -43,6 +43,10 @@ case ${clst_mainarch} in # || exit 1 ;; hppa) + # We have to remove the previous image because the file is considered + # as a tape by palo and then not truncated but rewritten. + rm -f /netboot.hppa + palo \ -k /kernel \ -r /initrd.gz \ diff --git a/targets/netboot/netboot-image.sh b/targets/netboot/netboot-image.sh index 05c52af9..02e2a23e 100644 --- a/targets/netboot/netboot-image.sh +++ b/targets/netboot/netboot-image.sh @@ -1,16 +1,21 @@ #!/bin/bash # Copyright 1999-2004 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo/src/catalyst/targets/netboot/netboot-image.sh,v 1.3 2004/10/11 14:19:30 zhen Exp $ +# $Header: /var/cvsroot/gentoo/src/catalyst/targets/netboot/netboot-image.sh,v 1.4 2005/01/11 15:22:41 zhen Exp $ /usr/sbin/env-update source /etc/profile -[ -f /tmp/envscript ] && source /tmp/envscript - -export USE="-* netboot" +if [ -f /tmp/envscript ] +then + source /tmp/envscript + rm -f /tmp/envscript +fi -emerge -k -b --nodeps genext2fs || exit 1 +#IMAGE_PATH=$1 +#shift +#TARBALL=$1 +#shift if [ -z "${IMAGE_PATH}" ] then @@ -21,73 +26,84 @@ fi # Install the netboot base system ROOT=${IMAGE_PATH} emerge -k -b --nodeps netboot-base || exit 1 -# Handle all strip calls here -function do_strip() { - strip --strip-unneeded "$@" -} - # Copy libs of a executable in the chroot function copy_libs() { - local ldd file="${1}" - # Figure out what libraries this file needs - local libs="$(readelf -d "${file}" | grep '(NEEDED)' | awk '{print $NF}')" - # Check if it's a dynamix exec, bail if it isnt - [ -z "${libs}" ] && return 0 + # Check if it's a dynamix exec + ldd ${1} > /dev/null 2>&1 || return - for lib in ${libs} + for lib in `ldd ${1} | awk '{ print $3 }'` do - # readelf shows [libblah.so] so we have to trim [] - lib=${lib:1:${#lib}-2} - - # don't scan the lib if it's already been copied over - [ -e "${IMAGE_PATH}/lib/${lib}" ] && continue - - # ldd changes output format over time - ldd="$(ldd "${file}" | grep ${lib})" - set -- ${ldd} - for ldd in "${@}" NF - do - [ "${ldd:0:1}" == "/" ] && break - done + if [ -e ${lib} ] + then + if [ ! -e ${IMAGE_PATH}/${lib} ] + then + copy_file ${lib} + [ -e "${IMAGE_PATH}/${lib}" ] && strip -R .comment -R .note ${IMAGE_PATH}/${lib} || echo "WARNING : Cannot strip lib ${IMAGE_PATH}/${lib} !" + fi + else + echo "WARNING : Some library was not found for ${lib} !" + fi + done + +} + + +function copy_symlink() { + + STACK=${2} + [ "${STACK}" = "" ] && STACK=16 || STACK=$((${STACK} - 1 )) + + if [ ${STACK} -le 0 ] + then + echo "WARNING : ${TARGET} : too many levels of symbolic links !" + return + fi + + [ ! -e ${IMAGE_PATH}/`dirname ${1}` ] && mkdir -p ${IMAGE_PATH}/`dirname ${1}` + [ ! -e ${IMAGE_PATH}/${1} ] && cp -vfdp ${1} ${IMAGE_PATH}/${1} - if [ "${ldd}" == "NF" ] + TARGET=`readlink -f ${1}` + if [ -h ${TARGET} ] then - echo "copy_lib: could not locate '${lib}'" + copy_symlink ${TARGET} ${STACK} else - copy_file ${ldd} + copy_file ${TARGET} fi - done + + } + function copy_file() { - local f="${1}" + + f="${1}" if [ ! -e "${f}" ] then - echo "copy_file: File '${f}' not found" - return 0 + echo "WARNING : File not found : ${f}" + continue fi - if [ -L "${f}" ] + [ ! -e ${IMAGE_PATH}/`dirname ${f}` ] && mkdir -p ${IMAGE_PATH}/`dirname ${f}` + [ ! -e ${IMAGE_PATH}/${f} ] && cp -vfdp ${f} ${IMAGE_PATH}/${f} + if [ -x ${f} -a ! -h ${f} ] then - cp -dp "${f}" "${IMAGE_PATH}/lib/" - local l="$(readlink "${f}")" - if [ ! -e "${l}" ] + copy_libs ${f} + strip -R .comment -R .note ${IMAGE_PATH}/${f} > /dev/null 2>&1 + elif [ -h ${f} ] then - l="$(dirname "${f}")/${l}" - fi - f="${l}" + copy_symlink ${f} fi - cp "${f}" "${IMAGE_PATH}/lib/" - do_strip "${IMAGE_PATH}/lib/$(basename "${f}")" } + # Copy the files needed in the chroot -loader="$(readelf -a ${IMAGE_PATH}/bin/busybox | grep 'ld-.*so' | awk '{print $NF}')" -copy_file ${loader/]} + copy_libs ${IMAGE_PATH}/bin/busybox -for f in "$@" ; do - copy_libs ${f} + +FILES="${@}" +for f in ${FILES} +do copy_file ${f} done @@ -101,8 +117,9 @@ cd ${IMAGE_PATH} rm -r var/db var/cache # Create the ramdisk +emerge -k -b genext2fs IMAGE_SIZE=$(du -s -k ${IMAGE_PATH} | cut -f1) -IMAGE_SIZE=$((IMAGE_SIZE + 200)) +IMAGE_SIZE=$((IMAGE_SIZE + 500)) IMAGE_INODES=$(find ${IMAGE_PATH} | wc -l) IMAGE_INODES=$((IMAGE_INODES + 100)) genext2fs -q -d "${IMAGE_PATH}" -b ${IMAGE_SIZE} -i ${IMAGE_INODES} /initrd || exit 1 diff --git a/targets/netboot/netboot-kernel.sh b/targets/netboot/netboot-kernel.sh index 9324c251..fe1d0c07 100644 --- a/targets/netboot/netboot-kernel.sh +++ b/targets/netboot/netboot-kernel.sh @@ -1,7 +1,7 @@ #!/bin/bash # Copyright 1999-2004 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo/src/catalyst/targets/netboot/Attic/netboot-kernel.sh,v 1.4 2004/10/22 04:23:16 wolf31o2 Exp $ +# $Header: /var/cvsroot/gentoo/src/catalyst/targets/netboot/Attic/netboot-kernel.sh,v 1.5 2005/01/11 15:22:41 zhen Exp $ /usr/sbin/env-update source /etc/profile @@ -15,10 +15,18 @@ export USE_ORDER="env:conf:defaults" mkdir -p ${GK_BINARIES} BUILD_KERNEL=1 +CONFIG_MD5_EQUAL=0 -if [ -n "${clst_KERNCACHE}" ] +GK_PKGDIR="$(portageq envvar PKGDIR)/All/genkernel" + +if [ -e "${GK_PKGDIR}/config-md5" -a "`md5sum ${CONFIG}`" = "$(< ${GK_PKGDIR}/config-md5)" ] +then + CONFIG_MD5_EQUAL=1 + echo "Using the cached kernel since your .config didn't changed." +fi + +if [ -n "${clst_KERNCACHE}" -a ${CONFIG_MD5_EQUAL} -eq 1 ] then - GK_PKGDIR="$(portageq envvar PKGDIR)/All/genkernel" mkdir -p ${GK_PKGDIR} if [ -f ${GK_PKGDIR}/kernel ] && [ -d ${GK_PKGDIR}/lib ] then @@ -32,9 +40,6 @@ if [ ${BUILD_KERNEL} -eq 1 ] then # setup genkernel emerge ${clst_myemergeopts} genkernel || exit 1 - # Fix dumb genkernel bug (#64514) - sed -e "/BUILD_INITRD/{s/&&/& (/ - s/$/ )/ }" -i /usr/share/genkernel/gen_package.sh # Build the kernel ! emerge ${clst_myemergeopts} ${SOURCES} || exit 1 @@ -47,10 +52,9 @@ then --minkernpackage=${GK_BINARIES}/kernel.tar.bz2 \ kernel || exit 1 - find ${GK_BINARIES}/lib \ - -name '*.o' -o -name '*.ko' \ - -exec strip -R .comment -R .note {} \; \ - || exit 1 + # DO NOT STRIP MODULES !!! It makes them unloadable ! + + kernname="$(tar -tjf ${GK_BINARIES}/kernel.tar.bz2)" tar -jxf ${GK_BINARIES}/kernel.tar.bz2 -C ${GK_BINARIES} mv ${GK_BINARIES}/{${kernname},kernel} || exit 1 @@ -65,6 +69,8 @@ then ;; esac fi + + md5sum "${CONFIG}" > "${GK_PKGDIR}/config-md5" fi cp ${GK_BINARIES}/kernel / || exit 1 diff --git a/targets/netboot/netboot.sh b/targets/netboot/netboot.sh index 14a7026f..fafc5d06 100644 --- a/targets/netboot/netboot.sh +++ b/targets/netboot/netboot.sh @@ -1,7 +1,7 @@ #!/bin/bash # Copyright 1999-2004 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo/src/catalyst/targets/netboot/Attic/netboot.sh,v 1.5 2004/10/12 18:01:22 zhen Exp $ +# $Header: /var/cvsroot/gentoo/src/catalyst/targets/netboot/Attic/netboot.sh,v 1.6 2005/01/11 15:22:41 zhen Exp $ export GK_BINARIES=/var/tmp/gk_binaries export IMAGE_PATH=/tmp/image @@ -43,11 +43,11 @@ case ${cmd} in if [ ! -z "${1}" ] then mkdir -p ${clst_chroot_path}/etc/busybox/${clst_CHOST} - cp ${1} ${clst_chroot_path}/etc/busybox/${clst_CHOST}/busybox.config + cp -v ${1} ${clst_chroot_path}/etc/busybox/${clst_CHOST}/busybox.config fi cp ${scriptdir}/netboot-busybox.sh ${clst_chroot_path}/tmp - ${clst_CHROOT} ${clst_chroot_path} /tmp/netboot-busybox.sh || exit 1 + ${clst_CHROOT} ${clst_chroot_path} /tmp/netboot-busybox.sh "${1}" || exit 1 rm -f ${clst_chroot_path}/tmp/netboot-busybox.sh ;; -- 2.26.2