wok-next annotate memtest/stuff/pack @ rev 15189
Add memtest-serial (again)
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sun Aug 25 18:12:50 2013 +0000 (2013-08-25) |
parents | b0e9e83532e2 |
children | b6771e9696d7 |
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@13269 | 4 cat >> $0 <<EOM |
pascal@15188 | 5 $(dd if=$1 bs=512 count=1 conv=sync | cat - $2 | gzip -9 | uuencode -m -) |
pascal@13269 | 6 EOT |
pascal@13269 | 7 EOM |
pascal@15189 | 8 x=$(grep -s packed_syssize ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') |
pascal@15189 | 9 [ -n "$x" ] && sed -i "s/XXXP/$((513+0x$x))/" $0 || sed -i s="/XXXP$/d" $0 |
pascal@15189 | 10 x=$(grep -s original_syssize ${2/.bin/.lst}|sed '$!d;s/.*t:\([^ ]*\).*/\1/') |
pascal@15189 | 11 [ -n "$x" ] && sed -i "s/XXXO/$((513+0x$x))/" $0 || sed -i s="/XXXO$/d" $0 |
pascal@15188 | 12 helpmsg=$(sed '/helpmsg:/!d{n;s/ [0-9]* \([^ ]*\).*/\1/}' ${1/.bin/.lst} | sed '$!d') |
pascal@15188 | 13 sed -i "s/YYY/$((0x$helpmsg))/" $0 |
pascal@15188 | 14 sed -i "s/ZZZ/$((496-0x$helpmsg))/" $0 |
pascal@13269 | 15 sed -i '/--build/,/^fi/d' $0 |
pascal@13269 | 16 exit |
pascal@13269 | 17 fi |
pascal@13269 | 18 |
pascal@13269 | 19 store() |
pascal@13269 | 20 { |
pascal@13269 | 21 n=$1 |
pascal@15188 | 22 for i in $(seq 1 ${4:-2}); do |
pascal@13269 | 23 printf '\\\\x%02X' $(($n & 255)) |
pascal@13269 | 24 n=$(($n >> 8)) |
pascal@13269 | 25 done | xargs echo -en | dd conv=notrunc bs=1 of=$2 seek=$3 |
pascal@13269 | 26 } |
pascal@13269 | 27 |
pascal@13269 | 28 compress() |
pascal@13269 | 29 { |
pascal@14798 | 30 xz -z -e --format=lzma --lzma1=mode=normal --stdout |
pascal@13269 | 31 } |
pascal@13269 | 32 |
pascal@13269 | 33 main() |
pascal@13269 | 34 { |
pascal@15188 | 35 uudecode | gunzip >$2 |
pascal@15188 | 36 dd if=$1 bs=1 skip=497 seek=497 count=15 of=$2 conv=notrunc |
pascal@13289 | 37 setup="$(echo $(od -j 497 -N 1 -dAn $1))" |
pascal@13287 | 38 syssize="$(echo $(od -j 500 -N 2 -dAn $1))" |
pascal@13269 | 39 dd if=$1 bs=512 count=$setup skip=1 | compress >>$2 |
pascal@13269 | 40 dd if=$1 bs=16 count=$syssize skip=$((32*(1+$setup))) | compress >>$2 |
pascal@13269 | 41 size=$(stat -c %s $2) |
pascal@15189 | 42 store $((($size-2560+15)/16)) $2 XXXP |
pascal@15189 | 43 store $syssize $2 XXXO |
pascal@15189 | 44 store $((($size-2560+15)/16)) $2 500 |
pascal@13269 | 45 store 4 $2 497 1 |
pascal@15188 | 46 store $((($size+511)/512)) $2 4 |
pascal@15188 | 47 store $((($size+15)/16)) $2 14 |
pascal@15188 | 48 echo -en "$3" | dd conv=notrunc bs=1 seek=YYY of=$2 count=ZZZ |
pascal@13269 | 49 } |
pascal@13269 | 50 |
pascal@15188 | 51 HELP="$(unix2dos <<EOT |
pascal@15188 | 52 Memtest86+ is an endless advanced memory diagnostic tool released under the |
pascal@15188 | 53 terms of the Gnu Public License (GPL). |
pascal@15188 | 54 |
pascal@15188 | 55 EOT |
pascal@15188 | 56 )" |
pascal@15188 | 57 main $1 ${2:-$1.packed} "${3:-$HELP}" 2>/dev/null <<EOT |