scripts/targets/Linux-arm

177 lines
3.6 KiB
Plaintext

#$Id$
#Copyright (c) 2008-2016 Pierre Pronchery <khorben@defora.org>
#variables
[ -z "$CHMOD" ] && CHMOD="chmod"
[ -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
#XXX hardcoded
. "$(dirname '$0')/Apps/Devel/src/scripts/scripts-git/targets/Linux"
#functions
#private
#image_ramdisk
_image_ramdisk_pre()
{
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
}
_image_ramdisk_post()
{
_create_directories "bin" "dev" "lib" "proc" "mnt/root" \
|| exit 2
echo
echo -n "Fixing installation paths:"
echo -n " /lib/libc.so"
$DEBUG $MV "$DESTDIR$PREFIX/lib/libc.so.0.0" \
"$DESTDIR/lib/libc.so.0.0" || exit 2
$DEBUG $LN -s "libc.so.0.0" "$DESTDIR/lib/libc.so" || exit 2
$DEBUG $LN -s "libc.so.0.0" "$DESTDIR/lib/libc.so.0" || exit 2
$DEBUG $LN -s "/lib/libc.so.0.0" "$DESTDIR$PREFIX/lib/libc.so.0.0" \
|| exit 2
echo -n " /bin/sh"
$DEBUG $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
$DEBUG $CHMOD 755 "$DESTDIR/linuxrc"
echo
fi
echo
echo -n "Building ramdisk image:"
$DEBUG $MKFS "$IMAGE_FILE" || exit 2
echo
$DEBUG $DU "$IMAGE_FILE"
echo
echo -n "Compressing ramdisk:"
$DEBUG $GZIP "$IMAGE_FILE" || exit 2
$DEBUG $MV "$IMAGE_FILE.gz" "$IMAGE_FILE" || exit 2
echo
$DEBUG $DU "$IMAGE_FILE"
}
#image_rootfs
_image_rootfs_pre()
{
#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
}
_image_rootfs_post()
{
_create_directories "bin" "dev" "etc" "lib" "sbin" || exit 2
echo
echo -n "Fixing installation paths:"
for i in /lib/libc.so /bin/sh; do
echo -n " $i"
$DEBUG $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" && $DEBUG $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
$DEBUG $CHMOD 755 "$DESTDIR/sbin/init"
echo
fi
echo
echo "Building rootfs image:"
$DEBUG $MKFS "$IMAGE_FILE" || exit 2
$DEBUG $DU "$IMAGE_FILE"
echo
echo "Building tarball:"
OLDPWD="$PWD"
(cd "$DESTDIR" && $DEBUG $TAR -cvzf "$OLDPWD/$IMAGE_FILE.tar.gz" .) \
| while read filename; do
echo -en "\r$filename"
done || (echo && exit 2)
echo -en "\r"
$DEBUG $DU "$IMAGE_FILE.tar.gz"
}
#public
#_image_post
_image_post()
{
case "$IMAGE_TYPE" in
"ramdisk")
_image_ramdisk_post
;;
"rootfs"|*)
_image_rootfs_post
;;
esac
}
#_image_pre
_image_pre()
{
case "$IMAGE_TYPE" in
"ramdisk")
_image_ramdisk_pre
;;
"rootfs"|*)
_image_rootfs_pre
;;
esac
}