wok-6.x annotate memtest/stuff/pack @ rev 24682
updated iw (5.4 -> 5.16)
author | Hans-G?nter Theisgen |
---|---|
date | Sat Mar 12 10:13:52 2022 +0100 (2022-03-12) |
parents | 9ca81337dc6e |
children | 608a017317a8 |
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@19404 | 6 x=$(grep -s setup_byte$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') |
pascal@19404 | 7 [ -n "$x" ] && sed -i "s/XXXSB/$((513+0x$x))/" $0 || sed -i "/XXXSB/d" $0 |
pascal@19404 | 8 x=$(grep -s setup_word$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') |
pascal@19404 | 9 [ -n "$x" ] && sed -i "s/XXXSW/$((514+0x$x))/" $0 || sed -i "/XXXSW/d" $0 |
pascal@19404 | 10 x=$(grep -s setup_para$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') |
pascal@19404 | 11 [ -n "$x" ] && sed -i "s/XXXSP/$((514+0x$x))/" $0 || sed -i "/XXXSP/d" $0 |
pascal@19404 | 12 x=$(grep -s setup_seg$ ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') |
pascal@19404 | 13 [ -n "$x" ] && sed -i "s/XXXSS/$((513+0x$x))/" $0 || sed -i "/XXXSS/d" $0 |
pascal@19404 | 14 grep -q BFF401 ${2/.bin/.lst} && sed -i 's/512 skip/500 skip/;s/1000 -/&32 - /' $0 |
pascal@19404 | 15 grep -q 83C60D ${2/.bin/.lst} && sed -i 's/ | dd bs=1 skip=13//' $0 |
pascal@19920 | 16 helpmsg=$(grep -s helpmsg$ ${1/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') |
pascal@19920 | 17 helpend=$(grep -s helpend$ ${1/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') |
pascal@19920 | 18 if [ -n "$helpmsg" ]; then |
pascal@19920 | 19 sed -i "s/YYY/$((0x$helpmsg))/" $0 |
pascal@19941 | 20 sed -i "s/ZZZ/$((0x$helpend-0x$helpmsg))/" $0 |
pascal@19920 | 21 else |
pascal@19920 | 22 sed -i '/YYY/d' $0 |
pascal@19920 | 23 fi |
pascal@17223 | 24 cat >> $0 <<EOM |
pascal@19404 | 25 $(dd if=$1 bs=512 count=1 conv=sync 2> /dev/null | cat - $2 | gzip -9 | uuencode -m -) |
pascal@17223 | 26 EOT |
pascal@17223 | 27 EOM |
pascal@13269 | 28 sed -i '/--build/,/^fi/d' $0 |
pascal@13269 | 29 exit |
pascal@13269 | 30 fi |
pascal@13269 | 31 |
pascal@13269 | 32 store() |
pascal@13269 | 33 { |
pascal@13269 | 34 n=$1 |
pascal@15188 | 35 for i in $(seq 1 ${4:-2}); do |
pascal@13269 | 36 printf '\\\\x%02X' $(($n & 255)) |
pascal@13269 | 37 n=$(($n >> 8)) |
pascal@13269 | 38 done | xargs echo -en | dd conv=notrunc bs=1 of=$2 seek=$3 |
pascal@13269 | 39 } |
pascal@13269 | 40 |
pascal@24045 | 41 bits() |
pascal@24045 | 42 { |
pascal@24045 | 43 sed "/define PROP_$1/!d;s|.*PROP_...||" unlzma.S |
pascal@24045 | 44 } |
pascal@24045 | 45 |
pascal@13269 | 46 compress() |
pascal@13269 | 47 { |
pascal@24045 | 48 xz -z -e --format=raw --lzma1=lc=$(bits LC),lp=$(bits LP),pb=$(bits PB) --stdout |
pascal@13269 | 49 } |
pascal@13269 | 50 |
pascal@13269 | 51 main() |
pascal@13269 | 52 { |
pascal@15188 | 53 uudecode | gunzip >$2 |
pascal@15188 | 54 dd if=$1 bs=1 skip=497 seek=497 count=15 of=$2 conv=notrunc |
pascal@13289 | 55 setup="$(echo $(od -j 497 -N 1 -dAn $1))" |
pascal@15480 | 56 [ $setup -eq 0 ] && setup=4 |
pascal@19404 | 57 store $setup $2 XXXSB 1 |
pascal@19404 | 58 store $setup $2 XXXSW 1 |
pascal@19404 | 59 store $((32 * $setup)) $2 XXXSP |
pascal@19404 | 60 store $((0x1000 - 32*$setup)) $2 XXXSS |
pascal@19404 | 61 dd if=$1 bs=512 skip=1 | compress >>$2 |
pascal@13269 | 62 size=$(stat -c %s $2) |
pascal@19941 | 63 syssize=$((($size-512*($setup+1)+15)/16)) |
pascal@19941 | 64 store $(($syssize + 0x1000)) $2 XXXP |
pascal@19941 | 65 store $syssize $2 500 |
pascal@13269 | 66 store 4 $2 497 1 |
pascal@15188 | 67 store $((($size+511)/512)) $2 4 |
pascal@15188 | 68 store $((($size+15)/16)) $2 14 |
pascal@15480 | 69 echo -e "$3" | dd conv=notrunc bs=1 seek=YYY of=$2 count=ZZZ |
pascal@13269 | 70 } |
pascal@13269 | 71 |
pascal@15188 | 72 HELP="$(unix2dos <<EOT |
pascal@19941 | 73 Memtest86+ VERSION GPLv2 |
pascal@15188 | 74 EOT |
pascal@15188 | 75 )" |
pascal@15188 | 76 main $1 ${2:-$1.packed} "${3:-$HELP}" 2>/dev/null <<EOT |