wok-current annotate memtest/stuff/pack @ rev 19399
memtest: DOS shutdown
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat Sep 03 09:48:39 2016 +0200 (2016-09-03) |
parents | 3b334b26197f |
children | 50b423f7711b |
rev | line source |
---|---|
pascal@13269 | 1 #!/bin/sh |
pascal@13269 | 2 if [ "$1" == "--build" ]; then |
pascal@15188 | 3 set -- ${2:-bootloader.bin} ${3:-unpack.bin} |
pascal@19391 | 4 x=$(grep -s packed_syssize$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') |
pascal@19391 | 5 [ -n "$x" ] && sed -i "s/XXXP/$((513+0x$x))/" $0 || sed -i "/XXXP$/d" $0 |
pascal@19391 | 6 x=$(grep -s original_syssize$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') |
pascal@19391 | 7 [ -n "$x" ] && sed -i "s/XXXO/$((513+0x$x))/" $0 || sed -i "/XXXO$/d" $0 |
pascal@19391 | 8 x=$(grep -s original_setupsize$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') |
pascal@19391 | 9 [ -n "$x" ] && sed -i "s/XXXS/$((516+0x$x))/" $0 || sed -i "/XXXS$/d" $0 |
pascal@15188 | 10 helpmsg=$(sed '/helpmsg:/!d{n;s/ [0-9]* \([^ ]*\).*/\1/}' ${1/.bin/.lst} | sed '$!d') |
pascal@17223 | 11 helpend=$(sed '/helpend:/!d{n;s/ [0-9]* \([^ ]*\).*/\1/}' ${1/.bin/.lst} | sed '$!d') |
pascal@15188 | 12 sed -i "s/YYY/$((0x$helpmsg))/" $0 |
pascal@19196 | 13 sed -i "s/ZZZ/$((0x$helpend-0x$helpmsg-1))/" $0 |
pascal@17223 | 14 cat >> $0 <<EOM |
pascal@17223 | 15 $(dd if=$1 bs=512 count=1 conv=sync | cat - $2 | gzip -9 | uuencode -m -) |
pascal@17223 | 16 EOT |
pascal@17223 | 17 EOM |
pascal@13269 | 18 sed -i '/--build/,/^fi/d' $0 |
pascal@13269 | 19 exit |
pascal@13269 | 20 fi |
pascal@13269 | 21 |
pascal@13269 | 22 store() |
pascal@13269 | 23 { |
pascal@13269 | 24 n=$1 |
pascal@15188 | 25 for i in $(seq 1 ${4:-2}); do |
pascal@13269 | 26 printf '\\\\x%02X' $(($n & 255)) |
pascal@13269 | 27 n=$(($n >> 8)) |
pascal@13269 | 28 done | xargs echo -en | dd conv=notrunc bs=1 of=$2 seek=$3 |
pascal@13269 | 29 } |
pascal@13269 | 30 |
pascal@13269 | 31 compress() |
pascal@13269 | 32 { |
pascal@15367 | 33 xz -z -e --format=lzma --lzma1=mf=bt2 --stdout |
pascal@13269 | 34 } |
pascal@13269 | 35 |
pascal@13269 | 36 main() |
pascal@13269 | 37 { |
pascal@15188 | 38 uudecode | gunzip >$2 |
pascal@15188 | 39 dd if=$1 bs=1 skip=497 seek=497 count=15 of=$2 conv=notrunc |
pascal@13289 | 40 setup="$(echo $(od -j 497 -N 1 -dAn $1))" |
pascal@15480 | 41 [ $setup -eq 0 ] && setup=4 |
pascal@13287 | 42 syssize="$(echo $(od -j 500 -N 2 -dAn $1))" |
pascal@15480 | 43 [ $syssize -eq 0 ] && syssize=$((($(stat -c %s $1) + 15 - 512*($setup + 1))/16)) |
pascal@15193 | 44 store $syssize $2 XXXO |
pascal@15193 | 45 store $setup $2 XXXS 1 |
pascal@13269 | 46 dd if=$1 bs=512 count=$setup skip=1 | compress >>$2 |
pascal@13269 | 47 dd if=$1 bs=16 count=$syssize skip=$((32*(1+$setup))) | compress >>$2 |
pascal@13269 | 48 size=$(stat -c %s $2) |
pascal@15189 | 49 store $((($size-2560+15)/16)) $2 XXXP |
pascal@15189 | 50 store $((($size-2560+15)/16)) $2 500 |
pascal@13269 | 51 store 4 $2 497 1 |
pascal@15188 | 52 store $((($size+511)/512)) $2 4 |
pascal@15188 | 53 store $((($size+15)/16)) $2 14 |
pascal@15480 | 54 echo -e "$3" | dd conv=notrunc bs=1 seek=YYY of=$2 count=ZZZ |
pascal@13269 | 55 } |
pascal@13269 | 56 |
pascal@15188 | 57 HELP="$(unix2dos <<EOT |
pascal@19399 | 58 Memtest86+ VERSION is an endless advanced memory diagnostic tool (GPL). |
pascal@15188 | 59 |
pascal@15188 | 60 EOT |
pascal@15188 | 61 )" |
pascal@15188 | 62 main $1 ${2:-$1.packed} "${3:-$HELP}" 2>/dev/null <<EOT |