X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=mkjffs2.sh;h=216c6bdf79a1c1270c183e728fa75963df08e3f7;hb=4352e15f6b81c24fb45a5eb69ff5a4e73641ac3a;hp=a885a24818795160d281800b86058b1e117587f6;hpb=2ac9597cb8d18c5917ac4d77bcf7fe665627fabf;p=xodist diff --git a/mkjffs2.sh b/mkjffs2.sh index a885a24..216c6bd 100755 --- a/mkjffs2.sh +++ b/mkjffs2.sh @@ -1,6 +1,6 @@ #!/bin/bash -e # -# Copyright © 2008 Andres Salomon +# Copyright © 2008-2009 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 @@ -16,22 +16,49 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -. functions.sh +. ./functions.sh + +CONFIG_TYPE=generic usage() { echo "" 1>&2 - echo "Usage: $0 " 1>&2 + echo "Usage: $0 [] " 1>&2 + echo "" 1>&2 + echo "Options:" 1>&2 + echo " --config-type directory name in configs/ to use" 1>&2 + echo " --help display this help screen" 1>&2 echo "" 1>&2 exit 1 } -if [ "$#" != "2" ]; then - usage -fi - -ROOT_DIR=$1 -IMG_NAME=$2 +while test $# != 0 +do + case $1 in + --config-type) + CONFIG_TYPE=$2 + [ -d ./configs/${CONFIG_TYPE} ] || { + echo "Error: can't find directory './configs/${CONFIG_TYPE}/'!" 1>&2 + exit 2 + } + shift + ;; + --help|-h) + usage + ;; + *) + if [ "$#" != "2" ]; then + echo "Unknown option $1" 1>&2 + usage + else + ROOT_DIR=$1 + IMG_NAME=$2 + shift + fi + ;; + esac + shift +done if [ "${IMG_NAME}" == "${IMG_NAME/.img/.dat}" ]; then DAT_NAME=${IMG_NAME}.dat @@ -46,67 +73,117 @@ if [ ! -d "${ROOT_DIR}" ]; then fi check_for_cmds mkfs.jffs2 sumtool || exit 1 -create_fstab ${ROOT_DIR} jffs2 -create_ofwboot ${ROOT_DIR} jffs2 + +# create image's /etc/fstab +if [ ! -f ./configs/${CONFIG_TYPE}/fstab-jffs2 ]; then + echo "*** Unable to find fstab-jffs2!" 1>&2 + exit 1 +fi +sed 's/[[:space:]]#.*//' ./configs/${CONFIG_TYPE}/fstab-jffs2 > ${ROOT_DIR}/etc/fstab + +# TODO: this needs to go into an OFW package; here it's a hack +# create image's /boot/olpc.fth +if [ -f ./configs/${CONFIG_TYPE}/olpc.fth-jffs2 ]; then + cp ./configs/${CONFIG_TYPE}/olpc.fth-jffs2 ${ROOT_DIR}/boot/olpc.fth +fi create_jffs2() { root_dir="$1" out="$2" - # XXX: do we want to switch to lzo? (mkfs.jffs2 -X lzo) mkfs.jffs2 -n -e128KiB -r ${root_dir} -o ${out}.pre sumtool -n -p -e 128KiB -i ${out}.pre -o ${out} rm -f ${out}.pre } -do_sha256() -{ - f=$1 - eblocks=$((`stat --printf "%s\n" $f` / (128*1024))) - for b in $(seq 0 $(($eblocks - 1))); do - sha=$(dd status=noxfer bs=128KiB skip=$b count=1 if=$f 2>/dev/null | sha256sum | cut -d- -f1) - echo "eblock: `printf '%x' $b` sha256 $sha" >> ${IMG_NAME} - done -} - partition_map() { - # 0x190 * 128KiB = 50MiB boot, and the rest for root cat >${IMG_NAME}<>${IMG_NAME}<> ${IMG_NAME} + sed -ne 's/^mtd://p' configs/${CONFIG_TYPE}/fstab-jffs2 | \ + while read name mntpt fstype extra; do + size=$(echo $extra | sed -ne 's/.*[[:space:]]\+#[[:space:]]\+//p') + if [ "${size}" = "" ]; then + size="-1" + else + # size in fstab is in MB; convert to 128KiB chunks (in hex) + # MB * (1024/128) + size=$((size * 8)) + size=`printf "%x\n" $size` + fi + printf " $name $size" >> ${IMG_NAME} + done + printf "\n" >> ${IMG_NAME} + + # individual partitions + sed -ne 's/^mtd://p' configs/${CONFIG_TYPE}/fstab-jffs2 | \ + while read name mntpt fstype extra; do + cat >>${IMG_NAME}<>${IMG_NAME}</dev/null \ + | sha256sum | cut -d\ -f1) + echo "eblock: `printf '%x' $b` sha256 $sha" >> ${IMG_NAME} + done + cat >>${IMG_NAME}< ${DAT_NAME} -rm -f _boot.img _root.img + +# concat partitions, finish up +rm -f ${DAT_NAME} +sed -ne 's/^mtd://p' configs/${CONFIG_TYPE}/fstab-jffs2 | \ + while read name mntpt fstype extra; do + cat "_${name}.img" >> ${DAT_NAME} + rm -f "_${name}.img" +done + +exit 0