#$Id$ #Copyright (c) 2009 Pierre Pronchery #variables [ -z "$LD" ] && LD="$CC -shared -nostdlib" [ -z "$LN" ] && LN="ln -f" [ -z "$MKFS" ] && MKFS="mkfs.jffs2 -n -e 0x4000 -l -q -r $DESTDIR -X zlib -o" #includes . "`dirname $0`/Apps/Devel/src/scripts/targets/Linux" #functions #private #image_ramdisk _image_ramdisk() { USAGE="Options for $IMAGE_TYPE on $TARGET:\n\ IMAGE_FILE Where to write the filesystem image\n\ MKFS Command used to format the filesystem" #sanity check check "$USAGE" DU GZIP IMAGE_FILE MKFS target "install" || exit 2 _create_directories "bin" "dev" "lib" "proc" "mnt/root" echo echo -n "Fixing installation paths:" echo -n " /lib/libc.so" $MV "$DESTDIR$PREFIX/lib/libc.so.0.0" "$DESTDIR/lib/libc.so.0.0" \ || exit 2 $LN -s "libc.so.0.0" "$DESTDIR/lib/libc.so" || exit 2 $LN -s "libc.so.0.0" "$DESTDIR/lib/libc.so.0" || exit 2 $LN -s "/lib/libc.so.0.0" "$DESTDIR$PREFIX/lib/libc.so.0.0" \ || exit 2 echo -n " /bin/sh" $MV "$DESTDIR$PREFIX/bin/sh" "$DESTDIR/bin/sh" || exit 2 echo if [ ! -x "$DESTDIR/sbin/init" ]; then echo echo -n "Installing linuxrc:" cat > "$DESTDIR/linuxrc" << EOF #!/bin/sh echo "init called with arguments: \$@" echo "Falling back to interactive mode:" /bin/sh EOF chmod 755 "$DESTDIR/linuxrc" echo fi echo echo -n "Building ramdisk image:" $MKFS "$IMAGE_FILE" || exit 2 echo $DU "$IMAGE_FILE" echo echo -n "Compressing ramdisk:" $GZIP "$IMAGE_FILE" || exit 2 $MV "$IMAGE_FILE.gz" "$IMAGE_FILE" || exit 2 echo $DU "$IMAGE_FILE" } #image_rootfs _image_rootfs() { #FIXME make IMAGE_SIZE optional and use ext2 then USAGE="Options for $IMAGE_TYPE on $TARGET:\n\ IMAGE_FILE Where to write the filesystem image\n\ IMAGE_MODULES Path to a tar.gz archive of kernel modules (optional)\n\ MKFS Command used to format the filesystem" #sanity check check "$USAGE" DESTDIR DU GZIP IMAGE_FILE MKFS MV SUDO TAR target "install" || exit 2 _create_directories "bin" "dev" "etc" "lib" "sbin" echo echo -n "Fixing installation paths:" for i in /lib/libc.so /bin/sh; do echo -n " $i" $MV "$DESTDIR$PREFIX$i" "$DESTDIR$i" || exit 2 done echo echo echo -n "Creating device nodes:" for i in std pty console input fb; do echo -n " $i" (cd "$DESTDIR/dev" && $SUDO sh /sbin/MAKEDEV "$i") done echo if [ ! -z "$KERNEL_MODULES" ]; then echo echo "Installing kernel modules:" #progress -ef "$KERNEL_MODULES" -- gunzip -c \ $GZIP -dc "$KERNEL_MODULES" \ | (cd "$DESTDIR" && $TAR -xf -) || exit 2 fi if [ ! -x "$DESTDIR/sbin/init" ]; then echo echo -n "Installing init:" cat > "$DESTDIR/sbin/init" << EOF #!/bin/sh echo "init called with arguments: \$@" echo "Falling back to interactive mode:" /bin/sh EOF chmod 755 "$DESTDIR/sbin/init" echo fi echo echo "Building rootfs image:" $MKFS "$IMAGE_FILE" || exit 2 $DU "$IMAGE_FILE" echo echo "Building tarball:" OLDPWD="$PWD" (cd "$DESTDIR" && $TAR -cvzf "$OLDPWD/$IMAGE_FILE.tar.gz" .) \ | while read filename; do echo -en "\r$filename" done || (echo && exit 2) echo -en "\r" $DU "$IMAGE_FILE.tar.gz" } #public #target_image target_image() { case "$IMAGE_TYPE" in "ramdisk") _image_ramdisk ;; "rootfs"|*) _image_rootfs ;; esac }