|
@ -1,15 +1,43 @@ |
|
|
|
|
|
#!/bin/bash |
|
|
|
|
|
|
|
|
echo_header "Creating initrd data:" |
|
|
echo_header "Creating initrd data:" |
|
|
rm -rf $disksdir/initrd |
|
|
rm -rf $disksdir/initrd |
|
|
mkdir -p $disksdir/initrd/{dev,proc,sys,tmp,scsi,net,bin,etc,lib} |
|
|
mkdir -p $disksdir/initrd/{dev,proc,sys,tmp,scsi,net,bin,etc,lib} |
|
|
cd $disksdir/initrd; ln -s bin sbin; ln -s . usr |
|
|
cd $disksdir/initrd; ln -s bin sbin; ln -s . usr |
|
|
|
|
|
|
|
|
|
|
|
rock_targetdir="$base/target/$target/" |
|
|
|
|
|
rock_target="$target" |
|
|
|
|
|
|
|
|
|
|
|
rootdir="$disksdir/2nd_stage" |
|
|
|
|
|
targetdir="$disksdir/initrd" |
|
|
|
|
|
cross_compile="" |
|
|
|
|
|
if [ "$ROCKCFG_CROSSBUILD" = "1" ] ; then |
|
|
|
|
|
cross_compile="`find ${base}/ROCK/tools.cross/ -name "*-readelf"`" |
|
|
|
|
|
cross_compile="${cross_compile##*/}" |
|
|
|
|
|
cross_compile="${cross_compile%%readelf}" |
|
|
|
|
|
fi |
|
|
|
|
|
initrdfs="ext2fs" |
|
|
|
|
|
block_size="" |
|
|
|
|
|
ramdisk_size=12288 |
|
|
|
|
|
|
|
|
|
|
|
case ${initrdfs} in |
|
|
|
|
|
ext2fs|ext3fs|cramfs) |
|
|
|
|
|
initrd_img="${disksdir}/initrd.img" |
|
|
|
|
|
;; |
|
|
|
|
|
ramfs) |
|
|
|
|
|
initrd_img="${disksdir}/initrd.cpio" |
|
|
|
|
|
;; |
|
|
|
|
|
esac |
|
|
|
|
|
|
|
|
echo_status "Creating some device nodes" |
|
|
echo_status "Creating some device nodes" |
|
|
mknod dev/ram0 b 1 0 |
|
|
|
|
|
mknod dev/null c 1 3 |
|
|
|
|
|
mknod dev/zero c 1 5 |
|
|
|
|
|
mknod dev/tty c 5 0 |
|
|
|
|
|
mknod dev/console c 5 1 |
|
|
|
|
|
|
|
|
mknod ${targetdir}/dev/ram0 b 1 0 |
|
|
|
|
|
mknod ${targetdir}/dev/null c 1 3 |
|
|
|
|
|
mknod ${targetdir}/dev/zero c 1 5 |
|
|
|
|
|
mknod ${targetdir}/dev/tty c 5 0 |
|
|
|
|
|
mknod ${targetdir}/dev/console c 5 1 |
|
|
|
|
|
|
|
|
|
|
|
# this copies a set of programs and the necessary libraries into a |
|
|
|
|
|
# chroot environment |
|
|
|
|
|
|
|
|
echo_status "Create checkisomd5 binary" |
|
|
echo_status "Create checkisomd5 binary" |
|
|
cp -r ${base}/misc/isomd5sum ${base}/build/${ROCKCFG_ID}/ |
|
|
cp -r ${base}/misc/isomd5sum ${base}/build/${ROCKCFG_ID}/ |
|
@ -24,23 +52,54 @@ chroot ${base}/build/${ROCKCFG_ID}/ /compile_isomd5sum.sh |
|
|
cp ${base}/build/${ROCKCFG_ID}/isomd5sum/checkisomd5 bin/ |
|
|
cp ${base}/build/${ROCKCFG_ID}/isomd5sum/checkisomd5 bin/ |
|
|
rm -rf ${base}/build/${ROCKCFG_ID}/compile_isomd5sum.sh ${base}/build/${ROCKCFG_ID}/isomd5sum |
|
|
rm -rf ${base}/build/${ROCKCFG_ID}/compile_isomd5sum.sh ${base}/build/${ROCKCFG_ID}/isomd5sum |
|
|
echo_status "Copying and adjusting linuxrc scipt" |
|
|
echo_status "Copying and adjusting linuxrc scipt" |
|
|
cp ${base}/target/${target}/linuxrc.sh linuxrc |
|
|
|
|
|
chmod +x linuxrc |
|
|
|
|
|
|
|
|
cp ${base}/target/${target}/linuxrc.sh sbin/init |
|
|
|
|
|
chmod +x sbin/init |
|
|
sed -i -e "s,^STAGE_2_BIG_IMAGE=\"2nd_stage.tar.gz\"$,STAGE_2_BIG_IMAGE=\"${ROCKCFG_SHORTID}/2nd_stage.tar.gz\"," \ |
|
|
sed -i -e "s,^STAGE_2_BIG_IMAGE=\"2nd_stage.tar.gz\"$,STAGE_2_BIG_IMAGE=\"${ROCKCFG_SHORTID}/2nd_stage.tar.gz\"," \ |
|
|
-e "s,^STAGE_2_SMALL_IMAGE=\"2nd_stage_small.tar.gz\"$,STAGE_2_SMALL_IMAGE=\"${ROCKCFG_SHORTID}/2nd_stage_small.tar.gz\"," \ |
|
|
-e "s,^STAGE_2_SMALL_IMAGE=\"2nd_stage_small.tar.gz\"$,STAGE_2_SMALL_IMAGE=\"${ROCKCFG_SHORTID}/2nd_stage_small.tar.gz\"," \ |
|
|
linuxrc |
|
|
|
|
|
|
|
|
|
|
|
echo_status "Copy various helper applications." |
|
|
|
|
|
for file in ../2nd_stage/bin/{tar,gzip,bash2,bash,sh,mount,umount,ls,sed,cut,cp} \ |
|
|
|
|
|
../2nd_stage/bin/{cat,uname,rm,ln,mkdir,rmdir,gawk,awk,grep,sleep} \ |
|
|
|
|
|
../2nd_stage/sbin/{ip,hwscan,pivot_root,swapon,swapoff,udevd} \ |
|
|
|
|
|
../2nd_stage/usr/bin/{wget,find,expand,readlink,basename,tr} \ |
|
|
|
|
|
../2nd_stage/usr/sbin/lspci ; do |
|
|
|
|
|
programs="${programs} ${file#../2nd_stage}" |
|
|
|
|
|
cp ${file} bin/ |
|
|
|
|
|
|
|
|
sbin/init |
|
|
|
|
|
|
|
|
|
|
|
libdirs="${rootdir}/lib `sed -e"s,^\(.*\),${rootdir}\1," ${rootdir}/etc/ld.so.conf | tr '\n' ' '`" |
|
|
|
|
|
|
|
|
|
|
|
needed_libs() { |
|
|
|
|
|
local x="${1}" library |
|
|
|
|
|
|
|
|
|
|
|
${cross_compile}readelf -d ${x} 2>/dev/null | grep "(NEEDED)" | |
|
|
|
|
|
sed -e"s,.*Shared library: \[\(.*\)\],\1," | |
|
|
|
|
|
while read library ; do |
|
|
|
|
|
find ${libdirs} -name "${library}" 2>/dev/null | |
|
|
|
|
|
sed -e "s,^${rootdir},,g" | tr '\n' ' ' |
|
|
|
|
|
done |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
echo_status "Copying other files ... " |
|
|
|
|
|
for x in ${rock_targetdir}/initrd/initrd_* ; do |
|
|
|
|
|
[ -f ${x} ] || continue |
|
|
|
|
|
while read file target ; do |
|
|
|
|
|
file="${rootdir}/${file}" |
|
|
|
|
|
[ -e ${file} ] || continue |
|
|
|
|
|
|
|
|
|
|
|
while read f ; do |
|
|
|
|
|
tfile=${targetdir}/${target}${f#${file}} |
|
|
|
|
|
[ -e ${tfile} ] && continue |
|
|
|
|
|
|
|
|
|
|
|
if [ -d ${f} -a ! -L ${f} ] ; then |
|
|
|
|
|
mkdir -p ${tfile} |
|
|
|
|
|
continue |
|
|
|
|
|
else |
|
|
|
|
|
mkdir -p ${tfile%/*} |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
# if [ -b ${f} -o -c ${f} -o -p ${f} -o -L ${f} ] ; then |
|
|
|
|
|
cp -a ${f} ${tfile} |
|
|
|
|
|
# else |
|
|
|
|
|
# cp ${f} ${tfile} |
|
|
|
|
|
# fi |
|
|
|
|
|
|
|
|
|
|
|
file -L ${f} | grep -q ELF || continue |
|
|
|
|
|
libs="${libs} `needed_libs ${f}`" |
|
|
|
|
|
done < <( find "${file}" ) |
|
|
|
|
|
done < ${x} |
|
|
done |
|
|
done |
|
|
cp -a $build_root/etc/udev etc/ |
|
|
|
|
|
cp -a $build_root/lib/udev lib/ |
|
|
|
|
|
|
|
|
|
|
|
for x in modprobe.static modprobe.static.old insmod.static insmod.static.old ; do |
|
|
for x in modprobe.static modprobe.static.old insmod.static insmod.static.old ; do |
|
|
if [ -f ../2nd_stage/sbin/${x/.static/} ]; then |
|
|
if [ -f ../2nd_stage/sbin/${x/.static/} ]; then |
|
@ -59,7 +118,7 @@ echo_status "Copy scsi and network kernel modules." |
|
|
find lib/modules -type f -exec $STRIP --strip-debug {} \; |
|
|
find lib/modules -type f -exec $STRIP --strip-debug {} \; |
|
|
|
|
|
|
|
|
for x in ../2nd_stage/lib/modules/*/modules.{dep,pcimap,isapnpmap} ; do |
|
|
for x in ../2nd_stage/lib/modules/*/modules.{dep,pcimap,isapnpmap} ; do |
|
|
cp $x ${x#../2nd_stage/} || echo "not found: $x" ; |
|
|
|
|
|
|
|
|
cp $x ${x#../2nd_stage/} || echo_status "not found: $x" ; |
|
|
done |
|
|
done |
|
|
|
|
|
|
|
|
for x in lib/modules/*/kernel/drivers/{scsi,net}; do |
|
|
for x in lib/modules/*/kernel/drivers/{scsi,net}; do |
|
@ -68,78 +127,82 @@ done |
|
|
rm -f lib/modules/[0-9]*/kernel/drivers/scsi/{st,scsi_debug}.{o,ko} |
|
|
rm -f lib/modules/[0-9]*/kernel/drivers/scsi/{st,scsi_debug}.{o,ko} |
|
|
rm -f lib/modules/[0-9]*/kernel/drivers/net/{dummy,ppp*}.{o,ko} |
|
|
rm -f lib/modules/[0-9]*/kernel/drivers/net/{dummy,ppp*}.{o,ko} |
|
|
|
|
|
|
|
|
echo_status "Copying necessary libraries" |
|
|
|
|
|
|
|
|
|
|
|
libs="/lib/ld-linux.so.2 /usr/lib/libpopt.so.0" |
|
|
|
|
|
# libpopt from checkisomd5 which is not in build/* |
|
|
|
|
|
for x in ${programs} ; do |
|
|
|
|
|
[ -e ./$x ] || continue |
|
|
|
|
|
file $x | grep -q ELF || continue |
|
|
|
|
|
libs="$libs `chroot ${base}/build/${ROCKCFG_ID} ldd $x 2>/dev/null | grep -v 'not a dynamic executable' | sed -e 's,^[\t ]*,,g' | cut -f 3 -d' '`" |
|
|
|
|
|
done |
|
|
|
|
|
|
|
|
|
|
|
while [ -n "$libs" ] ; do |
|
|
|
|
|
oldlibs=$libs |
|
|
|
|
|
|
|
|
echo_status "Copying required libraries ... " |
|
|
|
|
|
while [ -n "${libs}" ] ; do |
|
|
|
|
|
oldlibs=${libs} |
|
|
libs="" |
|
|
libs="" |
|
|
for x in $oldlibs ; do |
|
|
|
|
|
mkdir -p ./${x%/*} |
|
|
|
|
|
if [ ! -e ./$x ] ; then |
|
|
|
|
|
cp ${base}/build/${ROCKCFG_ID}/$x ./$x |
|
|
|
|
|
echo_status "- ${x##*/}" |
|
|
|
|
|
fi |
|
|
|
|
|
file $x | grep -q ELF || continue |
|
|
|
|
|
for y in `chroot ${base}/build/${ROCKCFG_ID} ldd $x 2>/dev/null | grep -v 'not a dynamic executable' | sed -e 's,^[\t ]*,,g' | cut -f 3 -d' '` ; do |
|
|
|
|
|
[ ! -e "./$y" ] && libs="$libs $y" |
|
|
|
|
|
|
|
|
for x in ${oldlibs} ; do |
|
|
|
|
|
[ -e ${targetdir}/${x} ] && continue |
|
|
|
|
|
mkdir -p ${targetdir}/${x%/*} |
|
|
|
|
|
cp ${rootdir}/${x} ${targetdir}/${x} |
|
|
|
|
|
file -L ${rootdir}/${x} | grep -q ELF || continue |
|
|
|
|
|
for y in `needed_libs ${rootdir}/${x}` ; do |
|
|
|
|
|
[ ! -e "${targetdir}/${y}" ] && libs="${libs} ${y}" |
|
|
done |
|
|
done |
|
|
done |
|
|
done |
|
|
done |
|
|
done |
|
|
|
|
|
|
|
|
echo_status "Creating links for identical files." |
|
|
|
|
|
|
|
|
echo_status "Creating links for identical files ..." |
|
|
while read ck fn |
|
|
while read ck fn |
|
|
do |
|
|
do |
|
|
if [ "$oldck" = "$ck" ] ; then |
|
|
|
|
|
echo_status "\`- Found $fn -> $oldfn." |
|
|
|
|
|
rm $fn ; ln -s ${oldfn#.} $fn |
|
|
|
|
|
|
|
|
# don't link empty files... |
|
|
|
|
|
if [ "${oldck}" = "${ck}" -a -s "${fn}" ] ; then |
|
|
|
|
|
echo_status "\`- Found ${fn#${targetdir}} -> ${oldfn#${targetdir}}." |
|
|
|
|
|
rm ${fn} ; ln -s /${oldfn#${targetdir}} ${fn} |
|
|
else |
|
|
else |
|
|
oldck=$ck ; oldfn=$fn |
|
|
|
|
|
|
|
|
oldck=${ck} ; oldfn=${fn} |
|
|
fi |
|
|
fi |
|
|
done < <( find -type f | xargs md5sum | sort ) |
|
|
|
|
|
|
|
|
done < <( find ${targetdir} -type f | xargs md5sum | sort ) |
|
|
|
|
|
|
|
|
cd .. |
|
|
cd .. |
|
|
|
|
|
|
|
|
echo_header "Creating initrd filesystem image: " |
|
|
|
|
|
|
|
|
|
|
|
ramdisk_size=16384 |
|
|
|
|
|
|
|
|
|
|
|
echo_status "Creating temporary files." |
|
|
|
|
|
tmpdir=initrd_$$.dir; mkdir -p $disksdir/$tmpdir; cd $disksdir |
|
|
|
|
|
dd if=/dev/zero of=initrd.img bs=1024 count=$ramdisk_size &> /dev/null |
|
|
|
|
|
eval tmpdev="`losetup -f 2>/dev/null`" |
|
|
|
|
|
if [ -z "$tmpdev" ] ; then |
|
|
|
|
|
for x in /dev/loop* /dev/loop/* ; do |
|
|
|
|
|
[ -b "${x}" ] || continue |
|
|
|
|
|
losetup ${x} 2>&1 >/dev/null || tmpdev="${x}" |
|
|
|
|
|
[ -n "${tmpdev}" ] && break |
|
|
|
|
|
done |
|
|
|
|
|
|
|
|
echo_header "Creating initrd filesystem image (${initrdfs}): " |
|
|
|
|
|
case "${initrdfs}" in |
|
|
|
|
|
cramfs) |
|
|
|
|
|
[ "${block_size}" == "" ] && block_size=4096 |
|
|
|
|
|
mkfs.cramfs -b ${block_size} ${targetdir} ${initrd_img} |
|
|
|
|
|
;; |
|
|
|
|
|
ramfs) |
|
|
|
|
|
# cp -a ${targetdir}/{linuxrc,init} |
|
|
|
|
|
( cd ${targetdir} ; find | cpio -o -c > ${initrd_img} ; ) |
|
|
|
|
|
;; |
|
|
|
|
|
ext2fs|ext3fs) |
|
|
|
|
|
[ "${block_size}" == "" ] && block_size=1024 |
|
|
|
|
|
block_count=$(( ( 1024 * ${ramdisk_size} ) / ${block_size} )) |
|
|
|
|
|
|
|
|
|
|
|
echo_status "Creating temporary files." |
|
|
|
|
|
tmpdir=`mktemp -d` ; mkdir -p ${tmpdir} |
|
|
|
|
|
dd if=/dev/zero of=${initrd_img} bs=${block_size} count=${block_count} &> /dev/null |
|
|
|
|
|
tmpdev="`losetup -f 2>/dev/null`" |
|
|
if [ -z "${tmpdev}" ] ; then |
|
|
if [ -z "${tmpdev}" ] ; then |
|
|
echo_error "No free loopback device found!" |
|
|
|
|
|
rm -f $tmpfile ; rmdir $tmpdir; exit 1 |
|
|
|
|
|
|
|
|
for x in /dev/loop* /dev/loop/* ; do |
|
|
|
|
|
[ -b "${x}" ] || continue |
|
|
|
|
|
losetup ${x} 2>&1 >/dev/null || tmpdev="${x}" |
|
|
|
|
|
[ -n "${tmpdev}" ] && break |
|
|
|
|
|
done |
|
|
|
|
|
if [ -z "${tmpdev}" ] ; then |
|
|
|
|
|
echo_status "No free loopback device found!" |
|
|
|
|
|
rm -f ${tmpfile} ; rmdir ${tmpdir}; exit 1 |
|
|
|
|
|
fi |
|
|
fi |
|
|
fi |
|
|
fi |
|
|
|
|
|
echo_status "Using loopback device $tmpdev." |
|
|
|
|
|
losetup "$tmpdev" initrd.img |
|
|
|
|
|
|
|
|
|
|
|
echo_status "Writing initrd image file." |
|
|
|
|
|
mke2fs -m 0 -N 360 -q $tmpdev &> /dev/null |
|
|
|
|
|
mount -t ext2 $tmpdev $tmpdir |
|
|
|
|
|
rmdir $tmpdir/lost+found/ |
|
|
|
|
|
cp -a initrd/* $tmpdir |
|
|
|
|
|
umount $tmpdir |
|
|
|
|
|
|
|
|
echo_status "Using loopback device ${tmpdev}." |
|
|
|
|
|
losetup "${tmpdev}" ${initrd_img} |
|
|
|
|
|
|
|
|
|
|
|
echo_status "Writing initrd image file." |
|
|
|
|
|
mkfs.${initrdfs:0:4} -b ${block_size} -m 0 -N 360 -q ${tmpdev} &> /dev/null |
|
|
|
|
|
mount -t ${initrdfs:0:4} ${tmpdev} ${tmpdir} |
|
|
|
|
|
rmdir ${tmpdir}/lost+found/ |
|
|
|
|
|
cp -a ${targetdir}/* ${tmpdir} |
|
|
|
|
|
umount ${tmpdir} |
|
|
|
|
|
|
|
|
|
|
|
echo_status "Removing temporary files." |
|
|
|
|
|
losetup -d ${tmpdev} |
|
|
|
|
|
rm -rf ${tmpdir} |
|
|
|
|
|
;; |
|
|
|
|
|
esac |
|
|
|
|
|
|
|
|
echo_status "Compressing initrd image file." |
|
|
echo_status "Compressing initrd image file." |
|
|
gzip -9 initrd.img |
|
|
|
|
|
mv initrd{.img,}.gz |
|
|
|
|
|
|
|
|
gzip -9 -c ${initrd_img} > ${initrd_img}.gz |
|
|
|
|
|
mv ${initrd_img%.img}{.img,}.gz |
|
|
|
|
|
|
|
|
echo_status "Removing temporary files." |
|
|
|
|
|
losetup -d $tmpdev |
|
|
|
|
|
rm -rf $tmpdir |
|
|
|
|
|
|
|
|
target="$rock_target" |