wok view memtest/stuff/pack @ rev 18232
linld: add tobzimage (again)
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Thu Jul 23 12:19:27 2015 +0200 (2015-07-23) |
parents | bd4321dee983 |
children | d9bf18af0e57 |
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 s="/XXXP$/d" $0
6 x=$(grep -s original_syssize ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/')
7 [ -n "$x" ] && sed -i "s/XXXO/$((513+0x$x))/" $0 || sed -i s="/XXXO$/d" $0
8 x=$(grep -s original_setupsize ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/')
9 [ -n "$x" ] && sed -i "s/XXXS/$((516+0x$x))/" $0 || sed -i s="/XXXS$/d" $0
10 helpmsg=$(sed '/helpmsg:/!d{n;s/ [0-9]* \([^ ]*\).*/\1/}' ${1/.bin/.lst} | sed '$!d')
11 helpend=$(sed '/helpend:/!d{n;s/ [0-9]* \([^ ]*\).*/\1/}' ${1/.bin/.lst} | sed '$!d')
12 sed -i "s/YYY/$((0x$helpmsg))/" $0
13 sed -i "s/ZZZ/$((0x$helpend-0x$helpmsg))/" $0
14 cat >> $0 <<EOM
15 $(dd if=$1 bs=512 count=1 conv=sync | cat - $2 | gzip -9 | uuencode -m -)
16 EOT
17 EOM
18 sed -i '/--build/,/^fi/d' $0
19 exit
20 fi
22 store()
23 {
24 n=$1
25 for i in $(seq 1 ${4:-2}); do
26 printf '\\\\x%02X' $(($n & 255))
27 n=$(($n >> 8))
28 done | xargs echo -en | dd conv=notrunc bs=1 of=$2 seek=$3
29 }
31 compress()
32 {
33 xz -z -e --format=lzma --lzma1=mf=bt2 --stdout
34 }
36 main()
37 {
38 uudecode | gunzip >$2
39 dd if=$1 bs=1 skip=497 seek=497 count=15 of=$2 conv=notrunc
40 setup="$(echo $(od -j 497 -N 1 -dAn $1))"
41 [ $setup -eq 0 ] && setup=4
42 syssize="$(echo $(od -j 500 -N 2 -dAn $1))"
43 [ $syssize -eq 0 ] && syssize=$((($(stat -c %s $1) + 15 - 512*($setup + 1))/16))
44 store $syssize $2 XXXO
45 store $setup $2 XXXS 1
46 dd if=$1 bs=512 count=$setup skip=1 | compress >>$2
47 dd if=$1 bs=16 count=$syssize skip=$((32*(1+$setup))) | compress >>$2
48 size=$(stat -c %s $2)
49 store $((($size-2560+15)/16)) $2 XXXP
50 store $((($size-2560+15)/16)) $2 500
51 store 4 $2 497 1
52 store $((($size+511)/512)) $2 4
53 store $((($size+15)/16)) $2 14
54 echo -e "$3" | dd conv=notrunc bs=1 seek=YYY of=$2 count=ZZZ
55 }
57 HELP="$(unix2dos <<EOT
58 Memtest86+ VERSION is an endless advanced memory diagnostic tool released under
59 the terms of the free Gnu Public License (GPL).
61 EOT
62 )"
63 main $1 ${2:-$1.packed} "${3:-$HELP}" 2>/dev/null <<EOT