|
|
@ -4,44 +4,60 @@ mainfunction="first_stage_mainfunction" |
|
|
|
|
|
|
|
first_stage_mainfunction () |
|
|
|
{ |
|
|
|
|
|
|
|
if [ $ROCKCFG_BUILD_TARGET != 1 ] ; then |
|
|
|
if [ "$ROCK_BUILD_TARGET" != 1 ] ; then |
|
|
|
echo "$xpkg can only be built with ./scripts/Build-Target!" |
|
|
|
false |
|
|
|
fi |
|
|
|
|
|
|
|
build_rock="/ROCK" |
|
|
|
disksdir="$build_rock/$target" |
|
|
|
|
|
|
|
echo "Creating initrd data:" |
|
|
|
rm -rf $disksdir/initrd |
|
|
|
mkdir -p $disksdir/initrd/{dev,proc,sys,tmp,scsi,net,bin,etc,lib} |
|
|
|
cd $disksdir/initrd; ln -s bin sbin; ln -s . usr |
|
|
|
initrd_config="$ROCKCFG_1ST_STAGE_INITRD" |
|
|
|
|
|
|
|
# make mount not complain |
|
|
|
touch etc/fstab |
|
|
|
rootdir="$root" |
|
|
|
build_rock="$root/ROCK" |
|
|
|
# disksdir="$build_rock/$target" |
|
|
|
disksdir="$build_rock/target" |
|
|
|
mkdir -p "$disksdir" |
|
|
|
targetdir="$disksdir/$initrd_config" |
|
|
|
|
|
|
|
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="`find ${build_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" |
|
|
|
initrd_img="${disksdir}/$initrd_config.img" |
|
|
|
;; |
|
|
|
ramfs) |
|
|
|
initrd_img="${disksdir}/initrd.cpio" |
|
|
|
initrd_img="${disksdir}/$initrd_config.cpio" |
|
|
|
;; |
|
|
|
esac |
|
|
|
|
|
|
|
|
|
|
|
# kernel="$( basename "$( readlink -mn $rootdir/usr/src/linux )" )" |
|
|
|
kernel="$( grep "[ =]$ROCKCFG_PKG_LINUX_DEFAULT " $base/config/$config/packages | cut -f6 -d" " )-rock" |
|
|
|
# echo "kernel $kernel" |
|
|
|
|
|
|
|
echo "Creating initrd data:" |
|
|
|
rm -rf $disksdir/$initrd_config |
|
|
|
mkdir -p $disksdir/$initrd_config/{dev,proc,sys,tmp,scsi,net,bin,etc,lib} |
|
|
|
cd $disksdir/$initrd_config # ; ln -s bin sbin ; ln -s . usr |
|
|
|
|
|
|
|
# this copies a set of programs and the necessary libraries into a |
|
|
|
# chroot environment |
|
|
|
|
|
|
|
# make mount not complain |
|
|
|
# touch etc/fstab |
|
|
|
echo "/dev/root / auto defaults 0 0" > etc/fstab |
|
|
|
|
|
|
|
# supress udev uig/gid warnings |
|
|
|
cp -vp $base/build/$ROCKCFG_ID/etc/{passwd,group} etc/ |
|
|
|
cp -vp $base/build/$ROCKCFG_ID/lib/libnss_files.so.* lib/ |
|
|
|
|
|
|
|
echo "Creating some device nodes" |
|
|
|
mknod ${targetdir}/dev/ram0 b 1 0 |
|
|
|
mknod ${targetdir}/dev/null c 1 3 |
|
|
@ -49,27 +65,18 @@ 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 "Create checkisomd5 binary" |
|
|
|
cp -r ${base}/misc/isomd5sum ${base}/build/${ROCKCFG_ID}/ |
|
|
|
cat >${base}/build/${ROCKCFG_ID}/compile_isomd5sum.sh <<EOF |
|
|
|
#!/bin/bash |
|
|
|
cd /isomd5sum |
|
|
|
make clean |
|
|
|
make CC=gcc |
|
|
|
EOF |
|
|
|
chmod +x ${base}/build/${ROCKCFG_ID}/compile_isomd5sum.sh |
|
|
|
chroot ${base}/build/${ROCKCFG_ID}/ /compile_isomd5sum.sh |
|
|
|
cp ${base}/build/${ROCKCFG_ID}/isomd5sum/checkisomd5 bin/ |
|
|
|
rm -rf ${base}/build/${ROCKCFG_ID}/compile_isomd5sum.sh ${base}/build/${ROCKCFG_ID}/isomd5sum |
|
|
|
echo "Copying and adjusting linuxrc scipt" |
|
|
|
cp $confdir/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\"," \ |
|
|
|
-e "s,^STAGE_2_SMALL_IMAGE=\"2nd_stage_small.tar.gz\"$,STAGE_2_SMALL_IMAGE=\"${ROCKCFG_SHORTID}/2nd_stage_small.tar.gz\"," \ |
|
|
|
sbin/init |
|
|
|
# echo "Create checkisomd5 binary" |
|
|
|
# cp -r ${base}/misc/isomd5sum ${base}/build/${ROCKCFG_ID}/ |
|
|
|
# cat >${base}/build/${ROCKCFG_ID}/compile_isomd5sum.sh <<EOF |
|
|
|
# #!/bin/bash |
|
|
|
# cd /isomd5sum |
|
|
|
# make clean |
|
|
|
# make CC=gcc |
|
|
|
# EOF |
|
|
|
# chmod +x ${base}/build/${ROCKCFG_ID}/compile_isomd5sum.sh |
|
|
|
# chroot ${base}/build/${ROCKCFG_ID}/ /compile_isomd5sum.sh |
|
|
|
# cp ${base}/build/${ROCKCFG_ID}/isomd5sum/checkisomd5 bin/ |
|
|
|
# rm -rf ${base}/build/${ROCKCFG_ID}/compile_isomd5sum.sh ${base}/build/${ROCKCFG_ID}/isomd5sum |
|
|
|
|
|
|
|
libdirs="${rootdir}/lib `sed -e"s,^\(.*\),${rootdir}\1," ${rootdir}/etc/ld.so.conf | tr '\n' ' '`" |
|
|
|
|
|
|
@ -85,9 +92,13 @@ needed_libs() { |
|
|
|
} |
|
|
|
|
|
|
|
libs="${libs} `needed_libs bin/checkisomd5`" |
|
|
|
# /usr/lib/libgcc_s.so.1 is required for ARM, but not auto-detected |
|
|
|
if [ "$ROCKCFG_ARCH" = arm ] ; then |
|
|
|
libs="${libs} /usr/lib/libgcc_s.so.1" |
|
|
|
fi |
|
|
|
|
|
|
|
echo "Copying other files ... " |
|
|
|
for x in $confdir/initrd/initrd_* ; do |
|
|
|
for x in $confdir/$initrd_config/initrd_* ; do |
|
|
|
[ -f ${x} ] || continue |
|
|
|
while read file target ; do |
|
|
|
file="${rootdir}/${file}" |
|
|
@ -104,18 +115,22 @@ for x in $confdir/initrd/initrd_* ; do |
|
|
|
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 |
|
|
|
cp -dp "${f}" "${tfile}" |
|
|
|
ls -l "$tfile" |
|
|
|
|
|
|
|
file -L ${f} | grep -q ELF || continue |
|
|
|
file -L "${f}" | grep -q ELF || continue |
|
|
|
libs="${libs} `needed_libs ${f}`" |
|
|
|
done < <( find "${file}" ) |
|
|
|
done < ${x} |
|
|
|
done < <( grep -v "^[ ]*#" ${x} ) |
|
|
|
done |
|
|
|
|
|
|
|
echo "Copying and adjusting linuxrc scipt" |
|
|
|
cp -dp $confdir/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\"," \ |
|
|
|
-e "s,^STAGE_2_SMALL_IMAGE=\"2nd_stage_small.tar.gz\"$,STAGE_2_SMALL_IMAGE=\"${ROCKCFG_SHORTID}/2nd_stage_small.tar.gz\"," \ |
|
|
|
sbin/init |
|
|
|
|
|
|
|
for x in modprobe.static modprobe.static.old insmod.static insmod.static.old ; do |
|
|
|
if [ -f ../2nd_stage/sbin/${x/.static/} ]; then |
|
|
|
rm -f bin/${x/.static/} |
|
|
@ -128,26 +143,51 @@ for x in modprobe.static modprobe.static.old insmod.static insmod.static.old ; d |
|
|
|
fi |
|
|
|
done |
|
|
|
|
|
|
|
add_module_to_initrd() { |
|
|
|
# adds a module and all it's dependencies to the initrd |
|
|
|
module_name="${1}" |
|
|
|
parameter="${2}" |
|
|
|
module_name=${module_name/.ko/} # just in case, shouldn't be |
|
|
|
|
|
|
|
for dependant_module in `get_module_dependencies ${module_name} | sort | uniq` ; do |
|
|
|
module="`find ${rootdir}/lib/modules/${kernel} -name "${dependant_module}.o" -o -name "${dependant_module}.ko"`" |
|
|
|
[ -f "${targetdir}/${module}" ] && return # skip dupes |
|
|
|
echo "Adding ${module}." |
|
|
|
mkdir -p ${targetdir}/${module%/*} |
|
|
|
cp ${module} ${targetdir}/${module} |
|
|
|
done |
|
|
|
|
|
|
|
echo "/sbin/modprobe ${module_name} ${parameter}" >> ${targetdir}/etc/conf/kernel |
|
|
|
} |
|
|
|
|
|
|
|
echo "Copy scsi and network kernel modules." |
|
|
|
tmptar="`mktemp`" ; tar cfT ${tmptar} /dev/null |
|
|
|
|
|
|
|
for x in $( cd ../2nd_stage ; ls -d lib/modules/*/kernel/drivers/{scsi,net} ) |
|
|
|
for x in $( cd ${rootdir} ; echo lib/modules/*/kernel/drivers/{scsi,net} ) |
|
|
|
do |
|
|
|
[ -e "../2nd_stage/${x}" ] && tar rf ${tmptar} -C ../2nd_stage ${x} |
|
|
|
[ -e "${rootdir}/${x}" ] && tar rf ${tmptar} -C ${rootdir} ${x} |
|
|
|
done |
|
|
|
tar xf ${tmptar} ; rm -f ${tmptar} |
|
|
|
|
|
|
|
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} |
|
|
|
|
|
|
|
[ -e lib/modules ] && find lib/modules -type f -exec $STRIP --strip-debug {} \; |
|
|
|
|
|
|
|
for x in ../2nd_stage/lib/modules/*/modules.{dep,pcimap,isapnpmap} ; do |
|
|
|
cp $x ${x#../2nd_stage/} || echo "not found: $x" ; |
|
|
|
done |
|
|
|
depmod -b ${targetdir} -F ${rootdir}/boot/System.map -v ${kernel} |
|
|
|
# for x in ${rootdir}/lib/modules/*/modules.{dep,pcimap,isapnpmap} ; do |
|
|
|
# cp $x ${x#*$rootdir/} || echo "not found: $x" ; |
|
|
|
# done |
|
|
|
|
|
|
|
for x in lib/modules/*/kernel/drivers/{scsi,net}; do |
|
|
|
[ -d $x ] && ln -s ${x#lib/modules/} lib/modules/ |
|
|
|
done |
|
|
|
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} |
|
|
|
|
|
|
|
if [ -e ${rootdir}/lib64 ] ; then |
|
|
|
# mixed 32/64-bit libraries are not supported |
|
|
|
echo "Creating /lib64 -> /lib symlink ... " |
|
|
|
ln -s lib $targetdir/lib64 |
|
|
|
fi |
|
|
|
|
|
|
|
echo "Copying required libraries ... " |
|
|
|
while [ -n "${libs}" ] ; do |
|
|
@ -156,7 +196,8 @@ while [ -n "${libs}" ] ; do |
|
|
|
for x in ${oldlibs} ; do |
|
|
|
[ -e ${targetdir}/${x} ] && continue |
|
|
|
mkdir -p ${targetdir}/${x%/*} |
|
|
|
cp ${rootdir}/${x} ${targetdir}/${x} |
|
|
|
cp -p ${rootdir}/${x} ${targetdir}/${x} |
|
|
|
ls -l ${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}" |
|
|
@ -178,22 +219,21 @@ done < <( find ${targetdir} -type f | xargs md5sum | sort ) |
|
|
|
|
|
|
|
cd .. |
|
|
|
|
|
|
|
# ramdisk_size=8192 |
|
|
|
# ramdisk_size="$(( $( du -s $targetdir --block-size=1K | cut -f1 ) + $( du -s $targetdir -block-size=1K | cut -f1 ) / 10 ))" |
|
|
|
# [ $ramdisk_size -lt 8192 ] && ramdisk_size=8192 |
|
|
|
echo "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 "Creating temporary files." |
|
|
|
block_count="$(( ( $( du -s $targetdir --block-size=$block_size | cut -f1 ) * 11 ) / 10 ))" |
|
|
|
echo "block_size=$block_size block_count=$block_count" |
|
|
|
tmpdir=`mktemp -d` ; mkdir -p ${tmpdir} |
|
|
|
echo "Creating temporary files in $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 |
|
|
@ -211,12 +251,12 @@ ext2fs|ext3fs) |
|
|
|
losetup "${tmpdev}" ${initrd_img} |
|
|
|
|
|
|
|
echo "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} |
|
|
|
mkfs.${initrdfs:0:4} -b ${block_size} -m 0 -q ${tmpdev} &> /dev/null |
|
|
|
mount -n -t ${initrdfs:0:4} ${tmpdev} ${tmpdir} |
|
|
|
rmdir ${tmpdir}/lost+found/ |
|
|
|
cp -a ${targetdir}/* ${tmpdir} |
|
|
|
umount ${tmpdir} |
|
|
|
|
|
|
|
umount -n ${tmpdir} |
|
|
|
|
|
|
|
echo "Removing temporary files." |
|
|
|
losetup -d ${tmpdev} |
|
|
|
rm -rf ${tmpdir} |
|
|
|