From 4012f4301660a23c872724a0a70f8024df093dd2 Mon Sep 17 00:00:00 2001 From: Andres Salomon Date: Tue, 19 Aug 2008 15:06:31 -0400 Subject: [PATCH] initial import Signed-off-by: Andres Salomon --- crcimg.pl | 11 +++ mkimg.sh | 267 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 278 insertions(+) create mode 100644 crcimg.pl create mode 100644 mkimg.sh diff --git a/crcimg.pl b/crcimg.pl new file mode 100644 index 0000000..37029f8 --- /dev/null +++ b/crcimg.pl @@ -0,0 +1,11 @@ +#!/usr/bin/perl -w + +use strict; +use String::CRC32; + +my ($crc, $buf); +while (read(STDIN, $buf, 0x20000) eq 0x20000) { + $crc = crc32($buf); + printf("%08lx\n", $crc); +} + diff --git a/mkimg.sh b/mkimg.sh new file mode 100644 index 0000000..a56e4b7 --- /dev/null +++ b/mkimg.sh @@ -0,0 +1,267 @@ +#!/bin/sh -e +# +# Copyright © 2008 Andres Salomon +# +# This file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# + + +IMG_NAME="DebOLPC" +ROOT_SIZE="512" +IMG_LABEL="DebOLPC" +ROOT_DIR="" +CRCIMG="./crcimg.pl" + + +PREREQ_CMDS="losetup dd parted mke2fs tune2fs grub" + +check_for_cmds() +{ + err=0 + for cmd in $PREREQ_CMDS; do + which $cmd >/dev/null || { + echo "Missing required command '$cmd'!" 1>&2 + err=1 + } + done + if [ "$err" = 1 ]; then + exit 1 + fi +} + +# @img - fs image to attach loop device to +# @offset - if the image is partitioned, the offset to attach at +# +# sets $LOOP_DEV with the path of the newly attached loop device +attach_loop() +{ + img="$1" + offset="$2" + + LOOP_DEV=$(losetup -f) + + if [ "$offset" != "" ]; then + losetup -o "$offset" "$LOOP_DEV" "$img" + else + losetup "$LOOP_DEV" "$img" + fi +} + +# @dev - the loop device to detach +detach_loop() +{ + losetup -d "$1" +} + +# @img - fs image to mount +# @type - fs type to mount +# @offset - if the image is partitioned, the offset to mount at +# +# sets $MOUNT_POINT with the path of the newly created (and mounted) dir +mk_mount() +{ + img="$1" + type="$2" + offset="$3" + + if [ "$offset" != "" ]; then + offset=",offset=$offset" + fi + + MOUNT_POINT=$(mktemp) + rm -f $MOUNT_POINT + mkdir $MOUNT_POINT + + mount "$img" "$MOUNT_POINT" -o loop$offset -t "$type" +} + +# @mntpt - directory to umount and delete +rm_mount() +{ + umount "$1" + rmdir "$1" +} + +# @img - image name to create +# @size - image size +mk_bootable_img() +{ + img="$1" + size="$2" + + # first, create a sparse image + minus_size=$(($size * 6 / 100)) + size=$(($size - $minus_size)) + dd if=/dev/zero of=$img bs=1M count=1 seek=$(($size - 1)) + + # fill in the partition table + parted -s "$img" "mklabel msdos" + parted -s "$img" "mkpart primary ext2 0 -1" + parted -s "$img" "set 1 boot on" +} + +# @mntpt - path to mounted root directory +# @fstype - the root filesystem type (in a form that 'mount' understands) +mk_fstab() +{ + mntpt="$1" + fstype="$2" + + cat >${mntpt}/etc/fstab<${mntpt}/boot/grub/menu.lst< ${IMG_NAME}.jffs2.crc +} + + +usage() +{ + echo "" 1>&2 + echo "Usage: $0 [] " 1>&2 + echo "" 1>&2 + echo "Options:" 1>&2 + echo " -l