1*458cbf0aSEnji Cooper# $FreeBSD$ 2*458cbf0aSEnji Cooper 3*458cbf0aSEnji Coopermkimg_blksz_list="512 4096" 4*458cbf0aSEnji Coopermkimg_format_list="qcow qcow2 raw vhd vhdf vmdk" 5*458cbf0aSEnji Coopermkimg_geom_list="1x1 63x255" 6*458cbf0aSEnji Coopermkimg_scheme_list="apm bsd ebr gpt mbr vtoc8" 7*458cbf0aSEnji Cooper 8*458cbf0aSEnji Cooperbootcode() 9*458cbf0aSEnji Cooper{ 10*458cbf0aSEnji Cooper case $1 in 11*458cbf0aSEnji Cooper bsd) echo 8192 ;; 12*458cbf0aSEnji Cooper gpt|mbr) echo 512 ;; 13*458cbf0aSEnji Cooper *) echo 0 ;; 14*458cbf0aSEnji Cooper esac 15*458cbf0aSEnji Cooper return 0 16*458cbf0aSEnji Cooper} 17*458cbf0aSEnji Cooper 18*458cbf0aSEnji Coopermkcontents() 19*458cbf0aSEnji Cooper{ 20*458cbf0aSEnji Cooper local byte count name 21*458cbf0aSEnji Cooper 22*458cbf0aSEnji Cooper byte=$1 23*458cbf0aSEnji Cooper count=$2 24*458cbf0aSEnji Cooper 25*458cbf0aSEnji Cooper name=_tmp-$byte-$count.bin 26*458cbf0aSEnji Cooper jot -b $byte $(($count/2)) > $name 27*458cbf0aSEnji Cooper echo $name 28*458cbf0aSEnji Cooper return 0 29*458cbf0aSEnji Cooper} 30*458cbf0aSEnji Cooper 31*458cbf0aSEnji Coopermakeimage() 32*458cbf0aSEnji Cooper{ 33*458cbf0aSEnji Cooper local blksz bootarg bootsz format geom nhds nsecs partarg pfx scheme 34*458cbf0aSEnji Cooper 35*458cbf0aSEnji Cooper format=$1 36*458cbf0aSEnji Cooper scheme=$2 37*458cbf0aSEnji Cooper blksz=$3 38*458cbf0aSEnji Cooper geom=$4 39*458cbf0aSEnji Cooper pfx=$5 40*458cbf0aSEnji Cooper shift 5 41*458cbf0aSEnji Cooper 42*458cbf0aSEnji Cooper nsecs=${geom%x*} 43*458cbf0aSEnji Cooper nhds=${geom#*x} 44*458cbf0aSEnji Cooper 45*458cbf0aSEnji Cooper bootsz=`bootcode $scheme` 46*458cbf0aSEnji Cooper if test $bootsz -gt 0; then 47*458cbf0aSEnji Cooper bootarg="-b `mkcontents B $bootsz`" 48*458cbf0aSEnji Cooper else 49*458cbf0aSEnji Cooper bootarg="" 50*458cbf0aSEnji Cooper fi 51*458cbf0aSEnji Cooper 52*458cbf0aSEnji Cooper partarg="" 53*458cbf0aSEnji Cooper for P in $*; do 54*458cbf0aSEnji Cooper partarg="$partarg -p $P" 55*458cbf0aSEnji Cooper done 56*458cbf0aSEnji Cooper if test -z "$partarg"; then 57*458cbf0aSEnji Cooper local swap ufs 58*458cbf0aSEnji Cooper swap="-p freebsd-swap::128K" 59*458cbf0aSEnji Cooper ufs="-p freebsd-ufs:=`mkcontents P 4194304`" 60*458cbf0aSEnji Cooper partarg="$ufs $swap" 61*458cbf0aSEnji Cooper fi 62*458cbf0aSEnji Cooper 63*458cbf0aSEnji Cooper imagename=$pfx-$geom-$blksz-$scheme.$format 64*458cbf0aSEnji Cooper 65*458cbf0aSEnji Cooper mkimg -y -f $format -o $imagename -s $scheme -P $blksz -H $nhds -T $nsecs \ 66*458cbf0aSEnji Cooper $bootarg $partarg 67*458cbf0aSEnji Cooper echo $imagename 68*458cbf0aSEnji Cooper return 0 69*458cbf0aSEnji Cooper} 70*458cbf0aSEnji Cooper 71*458cbf0aSEnji Coopermkimg_rebase() 72*458cbf0aSEnji Cooper{ 73*458cbf0aSEnji Cooper local baseline image result tmpfile update 74*458cbf0aSEnji Cooper 75*458cbf0aSEnji Cooper image=$1 76*458cbf0aSEnji Cooper result=$2 77*458cbf0aSEnji Cooper 78*458cbf0aSEnji Cooper baseline=$image.gz.uu 79*458cbf0aSEnji Cooper update=yes 80*458cbf0aSEnji Cooper 81*458cbf0aSEnji Cooper if test -f $baseline; then 82*458cbf0aSEnji Cooper tmpfile=_tmp-baseline 83*458cbf0aSEnji Cooper uudecode -p $baseline | gunzip -c > $tmpfile 84*458cbf0aSEnji Cooper if cmp -s $tmpfile $result; then 85*458cbf0aSEnji Cooper update=no 86*458cbf0aSEnji Cooper fi 87*458cbf0aSEnji Cooper fi 88*458cbf0aSEnji Cooper 89*458cbf0aSEnji Cooper if test $update = yes; then 90*458cbf0aSEnji Cooper # Prevent keyword expansion when writing the keyword. 91*458cbf0aSEnji Cooper (echo -n '# $'; echo -n FreeBSD; echo '$') > $baseline 92*458cbf0aSEnji Cooper gzip -c $result | uuencode $image.gz >> $baseline 93*458cbf0aSEnji Cooper fi 94*458cbf0aSEnji Cooper 95*458cbf0aSEnji Cooper rm $image $result _tmp-* 96*458cbf0aSEnji Cooper return 0 97*458cbf0aSEnji Cooper} 98*458cbf0aSEnji Cooper 99*458cbf0aSEnji Coopermkimg_test() 100*458cbf0aSEnji Cooper{ 101*458cbf0aSEnji Cooper local blksz format geom scheme 102*458cbf0aSEnji Cooper 103*458cbf0aSEnji Cooper geom=$1 104*458cbf0aSEnji Cooper blksz=$2 105*458cbf0aSEnji Cooper scheme=$3 106*458cbf0aSEnji Cooper format=$4 107*458cbf0aSEnji Cooper 108*458cbf0aSEnji Cooper case $scheme in 109*458cbf0aSEnji Cooper ebr|mbr) 110*458cbf0aSEnji Cooper bsd=`makeimage raw bsd $blksz $geom _tmp` 111*458cbf0aSEnji Cooper partinfo="freebsd:=$bsd" 112*458cbf0aSEnji Cooper ;; 113*458cbf0aSEnji Cooper *) 114*458cbf0aSEnji Cooper partinfo="" 115*458cbf0aSEnji Cooper ;; 116*458cbf0aSEnji Cooper esac 117*458cbf0aSEnji Cooper image=`makeimage $format $scheme $blksz $geom img $partinfo` 118*458cbf0aSEnji Cooper result=$image.out 119*458cbf0aSEnji Cooper hexdump -C $image > $result 120*458cbf0aSEnji Cooper if test "x$mkimg_update_baseline" = "xyes"; then 121*458cbf0aSEnji Cooper mkimg_rebase $image $result 122*458cbf0aSEnji Cooper else 123*458cbf0aSEnji Cooper baseline=`atf_get_srcdir`/$image 124*458cbf0aSEnji Cooper atf_check -s exit:0 cmp -s $baseline $result 125*458cbf0aSEnji Cooper fi 126*458cbf0aSEnji Cooper return 0 127*458cbf0aSEnji Cooper} 128*458cbf0aSEnji Cooper 129*458cbf0aSEnji Cooperatf_test_case rebase 130*458cbf0aSEnji Cooperrebase_body() 131*458cbf0aSEnji Cooper{ 132*458cbf0aSEnji Cooper local nm 133*458cbf0aSEnji Cooper 134*458cbf0aSEnji Cooper mkimg_update_baseline=yes 135*458cbf0aSEnji Cooper for nm in $mkimg_tests; do 136*458cbf0aSEnji Cooper ${nm}_body 137*458cbf0aSEnji Cooper done 138*458cbf0aSEnji Cooper return 0 139*458cbf0aSEnji Cooper} 140*458cbf0aSEnji Cooper 141*458cbf0aSEnji Cooperatf_init_test_cases() 142*458cbf0aSEnji Cooper{ 143*458cbf0aSEnji Cooper local B F G S nm 144*458cbf0aSEnji Cooper 145*458cbf0aSEnji Cooper for G in $mkimg_geom_list; do 146*458cbf0aSEnji Cooper for B in $mkimg_blksz_list; do 147*458cbf0aSEnji Cooper for S in $mkimg_scheme_list; do 148*458cbf0aSEnji Cooper for F in $mkimg_format_list; do 149*458cbf0aSEnji Cooper nm="${S}_${G}_${B}_${F}" 150*458cbf0aSEnji Cooper atf_test_case $nm 151*458cbf0aSEnji Cooper eval "${nm}_body() { mkimg_test $G $B $S $F; }" 152*458cbf0aSEnji Cooper mkimg_tests="${mkimg_tests} ${nm}" 153*458cbf0aSEnji Cooper atf_add_test_case $nm 154*458cbf0aSEnji Cooper done 155*458cbf0aSEnji Cooper done 156*458cbf0aSEnji Cooper done 157*458cbf0aSEnji Cooper done 158*458cbf0aSEnji Cooper 159*458cbf0aSEnji Cooper # XXX hack to make updating the baseline easier 160*458cbf0aSEnji Cooper if test "${__RUNNING_INSIDE_ATF_RUN}" != "internal-yes-value"; then 161*458cbf0aSEnji Cooper atf_add_test_case rebase 162*458cbf0aSEnji Cooper fi 163*458cbf0aSEnji Cooper} 164*458cbf0aSEnji Cooper 165