1458cbf0aSEnji Cooper 2458cbf0aSEnji Coopermkimg_blksz_list="512 4096" 3c78cd98bSOleksandr Tymoshenkomkimg_format_list="qcow qcow2 raw vhd vhdf vhdx vmdk" 4458cbf0aSEnji Coopermkimg_geom_list="1x1 63x255" 54ef1c6f7SMarius Stroblmkimg_scheme_list="apm bsd ebr gpt mbr" 6458cbf0aSEnji Cooper 7458cbf0aSEnji Cooperbootcode() 8458cbf0aSEnji Cooper{ 9458cbf0aSEnji Cooper case $1 in 10458cbf0aSEnji Cooper bsd) echo 8192 ;; 11458cbf0aSEnji Cooper gpt|mbr) echo 512 ;; 12458cbf0aSEnji Cooper *) echo 0 ;; 13458cbf0aSEnji Cooper esac 14458cbf0aSEnji Cooper return 0 15458cbf0aSEnji Cooper} 16458cbf0aSEnji Cooper 17458cbf0aSEnji Coopermkcontents() 18458cbf0aSEnji Cooper{ 19458cbf0aSEnji Cooper local byte count name 20458cbf0aSEnji Cooper 21458cbf0aSEnji Cooper byte=$1 22458cbf0aSEnji Cooper count=$2 23458cbf0aSEnji Cooper 24458cbf0aSEnji Cooper name=_tmp-$byte-$count.bin 25458cbf0aSEnji Cooper jot -b $byte $(($count/2)) > $name 26458cbf0aSEnji Cooper echo $name 27458cbf0aSEnji Cooper return 0 28458cbf0aSEnji Cooper} 29458cbf0aSEnji Cooper 30458cbf0aSEnji Coopermakeimage() 31458cbf0aSEnji Cooper{ 32458cbf0aSEnji Cooper local blksz bootarg bootsz format geom nhds nsecs partarg pfx scheme 33458cbf0aSEnji Cooper 34458cbf0aSEnji Cooper format=$1 35458cbf0aSEnji Cooper scheme=$2 36458cbf0aSEnji Cooper blksz=$3 37458cbf0aSEnji Cooper geom=$4 38458cbf0aSEnji Cooper pfx=$5 39458cbf0aSEnji Cooper shift 5 40458cbf0aSEnji Cooper 41458cbf0aSEnji Cooper nsecs=${geom%x*} 42458cbf0aSEnji Cooper nhds=${geom#*x} 43458cbf0aSEnji Cooper 44458cbf0aSEnji Cooper bootsz=`bootcode $scheme` 45458cbf0aSEnji Cooper if test $bootsz -gt 0; then 46458cbf0aSEnji Cooper bootarg="-b `mkcontents B $bootsz`" 47458cbf0aSEnji Cooper else 48458cbf0aSEnji Cooper bootarg="" 49458cbf0aSEnji Cooper fi 50458cbf0aSEnji Cooper 51458cbf0aSEnji Cooper partarg="" 52458cbf0aSEnji Cooper for P in $*; do 53458cbf0aSEnji Cooper partarg="$partarg -p $P" 54458cbf0aSEnji Cooper done 55458cbf0aSEnji Cooper if test -z "$partarg"; then 56458cbf0aSEnji Cooper local swap ufs 57458cbf0aSEnji Cooper swap="-p freebsd-swap::128K" 583ac62888SAlex Richardson ufs="-p freebsd-ufs:=$(atf_get_srcdir)/partition_data_4M.bin" 59458cbf0aSEnji Cooper partarg="$ufs $swap" 60458cbf0aSEnji Cooper fi 61458cbf0aSEnji Cooper 62458cbf0aSEnji Cooper imagename=$pfx-$geom-$blksz-$scheme.$format 63458cbf0aSEnji Cooper 64458cbf0aSEnji Cooper mkimg -y -f $format -o $imagename -s $scheme -P $blksz -H $nhds -T $nsecs \ 65458cbf0aSEnji Cooper $bootarg $partarg 66458cbf0aSEnji Cooper echo $imagename 67458cbf0aSEnji Cooper return 0 68458cbf0aSEnji Cooper} 69458cbf0aSEnji Cooper 70458cbf0aSEnji Coopermkimg_rebase() 71458cbf0aSEnji Cooper{ 72458cbf0aSEnji Cooper local baseline image result tmpfile update 73458cbf0aSEnji Cooper 74458cbf0aSEnji Cooper image=$1 75458cbf0aSEnji Cooper result=$2 76458cbf0aSEnji Cooper 77370d612fSMarcel Moolenaar baseline=$image.hex 78458cbf0aSEnji Cooper update=yes 79458cbf0aSEnji Cooper 80458cbf0aSEnji Cooper if test -f $baseline; then 81458cbf0aSEnji Cooper tmpfile=_tmp-baseline 82370d612fSMarcel Moolenaar sed -e '/^#.*/D' < $baseline > $tmpfile 83370d612fSMarcel Moolenaar if diff -u $tmpfile $result; then 84458cbf0aSEnji Cooper update=no 85458cbf0aSEnji Cooper fi 86458cbf0aSEnji Cooper fi 87458cbf0aSEnji Cooper 88458cbf0aSEnji Cooper if test $update = yes; then 89*3b5c9845SJose Luis Duran cat $result > $baseline 90458cbf0aSEnji Cooper fi 91458cbf0aSEnji Cooper 92458cbf0aSEnji Cooper rm $image $result _tmp-* 93458cbf0aSEnji Cooper return 0 94458cbf0aSEnji Cooper} 95458cbf0aSEnji Cooper 96458cbf0aSEnji Coopermkimg_test() 97458cbf0aSEnji Cooper{ 98458cbf0aSEnji Cooper local blksz format geom scheme 99458cbf0aSEnji Cooper 100458cbf0aSEnji Cooper geom=$1 101458cbf0aSEnji Cooper blksz=$2 102458cbf0aSEnji Cooper scheme=$3 103458cbf0aSEnji Cooper format=$4 104458cbf0aSEnji Cooper 105458cbf0aSEnji Cooper case $scheme in 106458cbf0aSEnji Cooper ebr|mbr) 107458cbf0aSEnji Cooper bsd=`makeimage raw bsd $blksz $geom _tmp` 108458cbf0aSEnji Cooper partinfo="freebsd:=$bsd" 109458cbf0aSEnji Cooper ;; 110458cbf0aSEnji Cooper *) 111458cbf0aSEnji Cooper partinfo="" 112458cbf0aSEnji Cooper ;; 113458cbf0aSEnji Cooper esac 114458cbf0aSEnji Cooper image=`makeimage $format $scheme $blksz $geom img $partinfo` 115458cbf0aSEnji Cooper result=$image.out 116458cbf0aSEnji Cooper hexdump -C $image > $result 117458cbf0aSEnji Cooper if test "x$mkimg_update_baseline" = "xyes"; then 118458cbf0aSEnji Cooper mkimg_rebase $image $result 119458cbf0aSEnji Cooper else 120458cbf0aSEnji Cooper baseline=`atf_get_srcdir`/$image 121370d612fSMarcel Moolenaar atf_check -s exit:0 diff -u $baseline $result 122458cbf0aSEnji Cooper fi 123458cbf0aSEnji Cooper return 0 124458cbf0aSEnji Cooper} 125458cbf0aSEnji Cooper 126458cbf0aSEnji Cooperatf_test_case rebase 127458cbf0aSEnji Cooperrebase_body() 128458cbf0aSEnji Cooper{ 129458cbf0aSEnji Cooper local nm 130458cbf0aSEnji Cooper 131458cbf0aSEnji Cooper mkimg_update_baseline=yes 132458cbf0aSEnji Cooper for nm in $mkimg_tests; do 133458cbf0aSEnji Cooper ${nm}_body 134458cbf0aSEnji Cooper done 135458cbf0aSEnji Cooper return 0 136458cbf0aSEnji Cooper} 137458cbf0aSEnji Cooper 138458cbf0aSEnji Cooperatf_init_test_cases() 139458cbf0aSEnji Cooper{ 140458cbf0aSEnji Cooper local B F G S nm 141458cbf0aSEnji Cooper 142458cbf0aSEnji Cooper for G in $mkimg_geom_list; do 143458cbf0aSEnji Cooper for B in $mkimg_blksz_list; do 144458cbf0aSEnji Cooper for S in $mkimg_scheme_list; do 145458cbf0aSEnji Cooper for F in $mkimg_format_list; do 146458cbf0aSEnji Cooper nm="${S}_${G}_${B}_${F}" 147458cbf0aSEnji Cooper atf_test_case $nm 148458cbf0aSEnji Cooper eval "${nm}_body() { mkimg_test $G $B $S $F; }" 149458cbf0aSEnji Cooper mkimg_tests="${mkimg_tests} ${nm}" 150458cbf0aSEnji Cooper atf_add_test_case $nm 151458cbf0aSEnji Cooper done 152458cbf0aSEnji Cooper done 153458cbf0aSEnji Cooper done 154458cbf0aSEnji Cooper done 155458cbf0aSEnji Cooper 156458cbf0aSEnji Cooper # XXX hack to make updating the baseline easier 157458cbf0aSEnji Cooper if test "${__RUNNING_INSIDE_ATF_RUN}" != "internal-yes-value"; then 158458cbf0aSEnji Cooper atf_add_test_case rebase 159458cbf0aSEnji Cooper fi 160458cbf0aSEnji Cooper} 161458cbf0aSEnji Cooper 162