wok-6.x view memtest/stuff/pack @ rev 19435

zerobin: add download button
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Oct 04 15:33:49 2016 +0200 (2016-10-04)
parents fd3dadf90ba9
children e4d1fb5556df
line source
1 #!/bin/sh
2 if [ "$1" == "--build" ]; then
3 set -- ${2:-bootloader.bin} ${3:-unpack.bin}
4 x=$(grep -s packed_syssize$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/')
5 [ -n "$x" ] && sed -i "s/XXXP/$((513+0x$x))/" $0 || sed -i "/XXXP$/d" $0
6 x=$(grep -s setup_byte$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/')
7 [ -n "$x" ] && sed -i "s/XXXSB/$((513+0x$x))/" $0 || sed -i "/XXXSB/d" $0
8 x=$(grep -s setup_word$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/')
9 [ -n "$x" ] && sed -i "s/XXXSW/$((514+0x$x))/" $0 || sed -i "/XXXSW/d" $0
10 x=$(grep -s setup_para$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/')
11 [ -n "$x" ] && sed -i "s/XXXSP/$((514+0x$x))/" $0 || sed -i "/XXXSP/d" $0
12 x=$(grep -s setup_seg$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/')
13 [ -n "$x" ] && sed -i "s/XXXSS/$((513+0x$x))/" $0 || sed -i "/XXXSS/d" $0
14 grep -q BFF401 ${2/.bin/.lst} && sed -i 's/512 skip/500 skip/;s/1000 -/&32 - /' $0
15 grep -q 83C60D ${2/.bin/.lst} && sed -i 's/ | dd bs=1 skip=13//' $0
16 helpmsg=$(sed '/helpmsg:/!d{n;s/ [0-9]* \([^ ]*\).*/\1/}' ${1/.bin/.lst} | sed '$!d')
17 helpend=$(sed '/helpend:/!d{n;s/ [0-9]* \([^ ]*\).*/\1/}' ${1/.bin/.lst} | sed '$!d')
18 sed -i "s/YYY/$((0x$helpmsg))/" $0
19 sed -i "s/ZZZ/$((0x$helpend-0x$helpmsg-1))/" $0
20 cat >> $0 <<EOM
21 $(dd if=$1 bs=512 count=1 conv=sync 2> /dev/null | cat - $2 | gzip -9 | uuencode -m -)
22 EOT
23 EOM
24 sed -i '/--build/,/^fi/d' $0
25 exit
26 fi
28 store()
29 {
30 n=$1
31 for i in $(seq 1 ${4:-2}); do
32 printf '\\\\x%02X' $(($n & 255))
33 n=$(($n >> 8))
34 done | xargs echo -en | dd conv=notrunc bs=1 of=$2 seek=$3
35 }
37 compress()
38 {
39 xz -z -e --format=lzma --lzma1=mf=bt2 --stdout | dd bs=1 skip=13
40 }
42 main()
43 {
44 uudecode | gunzip >$2
45 dd if=$1 bs=1 skip=497 seek=497 count=15 of=$2 conv=notrunc
46 setup="$(echo $(od -j 497 -N 1 -dAn $1))"
47 [ $setup -eq 0 ] && setup=4
48 syssize="$(echo $(od -j 500 -N 2 -dAn $1))"
49 [ $syssize -eq 0 ] && syssize=$((($(stat -c %s $1) + 15 - 512*($setup + 1))/16))
50 store $setup $2 XXXSB 1
51 store $setup $2 XXXSW 1
52 store $((32 * $setup)) $2 XXXSP
53 store $((0x1000 - 32*$setup)) $2 XXXSS
54 dd if=$1 bs=512 skip=1 | compress >>$2
55 size=$(stat -c %s $2)
56 store $((($size-2560+15)/16 + 0x1000)) $2 XXXP
57 store $((($size-2560+15)/16)) $2 500
58 store 4 $2 497 1
59 store $((($size+511)/512)) $2 4
60 store $((($size+15)/16)) $2 14
61 echo -e "$3" | dd conv=notrunc bs=1 seek=YYY of=$2 count=ZZZ
62 }
64 HELP="$(unix2dos <<EOT
65 Memtest86+ VERSION is an endless advanced memory diagnostic tool (GPL).
66 EOT
67 )"
68 main $1 ${2:-$1.packed} "${3:-$HELP}" 2>/dev/null <<EOT