wok view plop/stuff/pack @ rev 25283

updated roundup (1.6.1 -> 2.2.0)
author Hans-G?nter Theisgen
date Mon Jul 18 15:58:43 2022 +0100 (2022-07-18)
parents c4968381aed9
children 7f7bd3c9775e
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 x=$(grep -s setup_keep$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/')
15 [ -n "$x" ] && sed -i "s/XXXK1/1/" $0 || sed -i "/XXXK1/d" $0
16 [ -n "$x" ] && sed -i "s/skip=XXXK2 //" $0 || sed -i "s/XXXK2/1/" $0
17 [ -n "$x" ] && sed -i "s/+XXXK3//" $0 || sed -i "s/XXXK3/1/" $0
18 grep -q BFF401 ${2/.bin/.lst} && sed -i 's/512 skip/500 skip/;s/1000 -/&32 - /' $0
19 grep -q 83C60D ${2/.bin/.lst} && sed -i 's/ | dd bs=1 skip=13//' $0
20 helpmsg=$(grep -s helpmsg$ ${1/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/')
21 helpend=$(grep -s helpend$ ${1/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/')
22 if [ -n "$helpmsg" ]; then
23 sed -i "s/YYY/$((0x$helpmsg))/" $0
24 sed -i "s/ZZZ/$((0x$helpend-0x$helpmsg))/" $0
25 else
26 sed -i '/YYY/d' $0
27 fi
28 cat >> $0 <<EOM
29 $(dd if=$1 bs=512 count=1 conv=sync 2> /dev/null | cat - $2 | gzip -9 | uuencode -m -)
30 EOT
31 EOM
32 sed -i '/--build/,/^fi/d' $0
33 exit
34 fi
36 store()
37 {
38 n=$1
39 for i in $(seq 1 ${4:-2}); do
40 printf '\\\\x%02X' $(($n & 255))
41 n=$(($n >> 8))
42 done | xargs echo -en | dd conv=notrunc bs=1 of=$2 seek=$3
43 }
45 bits()
46 {
47 sed "/^#define PROP_$1/!d;s|.*PROP_...||" unlzma.S
48 }
50 compress()
51 {
52 xz -z -e --format=raw --lzma1=lc=$(bits LC),lp=$(bits LP),pb=$(bits PB) --stdout
53 }
55 main()
56 {
57 uudecode | gunzip >$2
58 dd if=$1 bs=1 skip=497 seek=497 count=15 of=$2 conv=notrunc
59 setup="$(echo $(od -j 497 -N 1 -dAn $1))"
60 [ $setup -eq 0 ] && setup=4
61 setup=$(($setup+XXXK1))
62 store $setup $2 XXXSB 1
63 store $setup $2 XXXSW 1
64 store $((32 * $setup)) $2 XXXSP
65 store $((0x1000 - 32*$setup)) $2 XXXSS
66 dd if=$1 bs=512 skip=XXXK2 | compress >>$2
67 size=$(stat -c %s $2)
68 syssize=$((($size-512*($setup+XXXK3)+15)/16))
69 store $(($syssize + 0x1000)) $2 XXXP
70 store $syssize $2 500
71 store 4 $2 497 1
72 store $((($size+511)/512)) $2 4
73 store $((($size+15)/16)) $2 14
74 echo -e "$3" | dd conv=notrunc bs=1 seek=YYY of=$2 count=ZZZ
75 }
77 HELP="$(unix2dos <<EOT
78 Plop Boot Manager VERSION
79 EOT
80 )"
81 main $1 ${2:-$1.packed} "${3:-$HELP}" 2>/dev/null <<EOT