Author: wmb Date: Sun Oct 16 01:21:46 2011 New Revision: 2611 URL: http://tracker.coreboot.org/trac/openfirmware/changeset/2611
Log: Ext2 filesystem - added test script.
Added: ofw/fs/ext2fs/ext2test.fth ofw/fs/ext2fs/ext2test.sh
Added: ofw/fs/ext2fs/ext2test.fth ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ ofw/fs/ext2fs/ext2test.fth Sun Oct 16 01:21:46 2011 (r2611) @@ -0,0 +1,109 @@ +\ OLPC boot script + +\ dev.laptop.org #6210 test script +\ Exercises several OFW features on an ext2 filesystem on a USB stick +\ see associated test.sh + +visible +no-page +start-logging + +.( test.fth ticket #6210 ofw ext2 filesystem tests ) cr + +show-aborts on + +.( test 0001 define u: ) cr +volume: u: + +.( test 0002 reference u: ) cr +u: + +\ .( test 0003 directory ) cr +\ dir + +\ .( test 0004 directory by name ) cr +\ dir *.fth + +.( test 0005 chdir down ) cr +chdir directory + +.( test 0006 directory of subdirectory after chdir ) cr +dir + +.( test 0007 chdir up ) cr +chdir .. + +.( test 0008 directory of main directory after chdir ) cr +dir + +.( test 0009 disk free ) cr +disk-free u:\ + +.( test 0010 display a file ) cr +more u:\hello + +.( test 0011 display a file with a hyphen in file name ) cr +more u:\hello-world + +.( test 0012 display a link ) cr +more u:\hello-link + +.( test 0013 directory of subdirectory by name ) cr +dir u:\directory + +.( test 0014 display a file in subdirectory ) cr +more u:\directory\hw + +.( test 0015 copy a file ) cr +copy u:\hello-world u:\copy + +.( test 0016 display the copy ) cr +more u:\copy + +.( test 0017 rename the copy ) cr +rename u:\copy u:\renamed + +.( test 0018 delete the renamed copy ) cr +del u:\renamed + +.( test 0019 delete a non-existent file ) cr +del u:\vapour + +: load-file ( "devspec" -- adr len ) + safe-parse-word + open-dev dup 0= abort" Can't open it" ( ih ) + >r ( r: ih ) + load-base " load" r@ $call-method ( len r: ih ) + r> close-dev ( len ) + load-base swap +; + +: calculate-md5 ( adr len -- adr len ) + $md5digest1 ; + +: print-md5 ( adr len -- ) + bounds ?do i c@ (.2) type loop space ; + +: md5sum ( "devspec" -- ) load-file calculate-md5 print-md5 ; + +.( test 0020 calculate md5sum of a test file ) cr +md5sum u:\hello-world cr + +.( test 0021 calculate md5sum of a test file and save to a file ) cr +del u:\hello-world.md5 +load-file u:\hello-world calculate-md5 to-file u:\hello-world.md5 print-md5 + +.( test 0022 dump forth dictionary to file ) cr +del u:\words.txt +to-file u:\words.txt words + +\ reference: forth/lib/tofile.fth +\ to-file u:\words words +\ append-to-file u:\words words + +.( done ) cr +save-log u:\ofw.log +stop-logging + +\ .( boot ) cr +\ boot n:\boot\olpc.fth
Added: ofw/fs/ext2fs/ext2test.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ ofw/fs/ext2fs/ext2test.sh Sun Oct 16 01:21:46 2011 (r2611) @@ -0,0 +1,160 @@ +#!/bin/bash +# dev.laptop.org #6210 test script +# +# Creates an ext2 filesystem on a USB stick for testing with OFW +# +# Instructions for use: +# - copy this file and ext2test.fth to a Linux machine +# - turn off X with 'telinit 4', +# - ensure that no USB stick is mounted +# - insert USB stick, wait seven seconds settling time, +# - execute this script "ext2test.sh /dev/sda", +# - remove USB stick, +# - insert in test laptop, +# - power up, +# - examine output. +# +set -e + +function help { + cat <<EOF +Usage: test.sh [options] device + --help display this help + --end N partition end specification for parted, -1s is the + default and means full size, or use a number followed + by s for a given number of sectors, see the parted(8) + unit command. + device the device you wish to write to, e.g. /dev/sdZ +EOF +} + +DEVICE= +END=-1s +while [ ! -z "${1}" ]; do + case "${1}" in + --end) + shift + END=${1} + shift + echo "test.sh: partition end to be set to ${END}" + ;; + --help) + shift + help + exit 0 + ;; + *) + DEVICE=${1} + shift +# if [ ! -e ${DEVICE} ]; then +# echo "test.sh: no such device ${DEVICE}" +# exit 1 +# fi + esac + +done + +if [ -z "${DEVICE}" ]; then + echo "test.sh: no device specified" + help + exit 1 +fi + +if [ ! -b "${DEVICE}" ]; then +echo REMAKING FILE +rm -f "${DEVICE}" +dd if=/dev/zero of=${DEVICE} bs=512 count=1 seek=8388000 2> /dev/null #8388608 +# dd if=/dev/zero of=${DEVICE} bs=512 count=1 seek=4194303 2> /dev/null +#dd if=/dev/zero of=${DEVICE} bs=512 count=1 seek=2097151 2> /dev/null +#dd if=/dev/zero of=${DEVICE} bs=512 count=1 seek=1050000 2> /dev/null +chmod 666 ${DEVICE} +fi +# if [ ! -b "${DEVICE}" -a ! -f "${DEVICE}" ]; then +# Need to parse ${END} to remove the trailing s if it exists, or if not, to change the bs units +# dd if=/dev/zero of=${DEVICE} bs=512 count=1 seek=${END} status=noxfer 2> /dev/null +# fi + +echo -n "zero overwrite partition table ... " +dd if=/dev/zero of=${DEVICE} bs=1024 count=256 status=noxfer conv=notrunc 2> /dev/null +echo "ok" + +echo -n "create new partition table ... " +/sbin/parted --script ${DEVICE} mklabel msdos +echo "ok" + +# if we do not do this, the old partition in /dev does not go away +echo -n "probe partition table ... " +/sbin/partprobe ${DEVICE} +echo "ok" + +# This commented-out block of code is unreliable +# echo -n "wait for old partition to go ... " +# declare -i c +# c=0 +# until [ ! -e ${DEVICE}1 ]; do +# sleep 0.1 +# echo -n . +# c=c+1 +# if [ ${c} -gt 10 ]; then +# # sometimes it needs a harder whack +# /sbin/partprobe -s > /dev/null 2> /dev/null +# sleep 0.1 +# fi +# done +# echo "ok" + +echo -n "create new partition ... " +echo /sbin/parted --script -- ${DEVICE} mkpart primary ext2 0 ${END} +/sbin/parted --script -- ${DEVICE} mkpart primary ext2 0 ${END} || true +echo "ok" + +if [ -b ${DEVICE} ] ; then + PARTITION=${DEVICE}1 + + echo -n "wait for new partition to arrive ... " + until [ -e ${PARTITION} ]; do sleep 0.1; echo -n .; done + echo "ok" +else + OFFSET=512 + PARTITION=`/sbin/losetup -o ${OFFSET} -f -s ${DEVICE}` + echo partition = $PARTITION +fi + +echo -n "make filesystem ... " +#/sbin/mke2fs -n -b 4096 -q ${PARTITION} +# /sbin/mke2fs -n -j -O dir_index,^huge_file -E resize=8G -m 1 -b 4096 -q ${PARTITION} +/sbin/mke2fs -n -j -O dir_index -m 1 -b 1024 -q ${PARTITION} +echo "made" + +# we occasionally get +# mount: you must specify the filesystem type +# despite having just created the filesystem +echo -n "mount filesystem ... " +until mount ${PARTITION} /mnt; do sleep 0.1; done +echo "mounted" + +echo -n "create test content and unmount ... " + +mkdir /mnt/boot +cp ext2test.fth /mnt/boot/olpc.fth + +cd /mnt +touch touched +echo hello > hello +echo hello world > hello-world +date > date +ln -s hello hello-link +mkdir directory +ln -s directory directory-link +touch directory/touched +echo hello world down here > directory/hw +mkfifo fifo +mknod node b 1 1 +cd +umount /mnt + +if [ ! -b ${DEVICE} ] ; then + /sbin/losetup -d ${PARTITION} +fi + +echo "finished"