#$Id$ #Copyright (c) 2009 Pierre Pronchery #variables [ -z "$LD" ] && LD="cc -shared -nostdlib" [ -z "$MKFS" ] && MKFS="mkfs.jffs2 -n -e 0x4000 -l -q -r $DESTDIR -X zlib -o" #includes source "`dirname $0`/Apps/Devel/src/scripts/targets/Linux" #functions #private #create_directories _create_directories() { echo echo -n "Creating missing directories:" while true; do echo -n " $1" $MKDIR "$DESTDIR/$1" || exit 2 shift || break done echo } #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 "dev" "proc" "mnt/cdrom" "sbin" 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() { 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 }