wok-tiny view linux/stuff/pack @ rev 140

linux: disable setup packing...
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Jul 04 20:33:53 2018 +0200 (2018-07-04)
parents 88e2011c8afe
children d22f6fcf51da
line source
1 #!/bin/sh
3 ddq()
4 {
5 dd "$@" 2> /dev/null
6 }
8 word()
9 {
10 n=$1; for i in $(seq 1 1 ${2:-2}); do
11 printf '\\\\x%02X' $(($n & 255))
12 n=$(($n >> 8))
13 done | xargs echo -en
14 }
16 store()
17 {
18 word $2 "$4" | ddq bs=1 conv=notrunc of="$3" seek=$(($1))
19 }
21 get()
22 {
23 echo $(od -j $(($1)) -N ${3:-2} -t u${3:-2} -An "$2")
24 }
26 if [ ! -s "$1" ]; then
27 cat << EOT
28 Usage: $0 bzImage [bootsector helper] [bootsector]
29 EOT
30 exit 1
31 fi
33 if which lz4 > /dev/null ; then
35 # boot + head param
36 param=$((514+$(get 0x201 $1 1)))
37 ddq if=$1 bs=1 count=$param > /tmp/setup$$
39 # unlz4 + data
40 ddq if=unpacklz4.bin >> /tmp/setup$$
41 setupsz=$(get 0x1F1 $1 1)
42 ddq if=$1 bs=1 skip=$param count=$(($setupsz*512-$param+512)) | \
43 lz4 -l -12 | ddq bs=4 skip=1 >> /tmp/setup$$
45 # version string
46 word $(get 0x20E $1) >> /tmp/setup$$
47 word $setupsz 1 >> /tmp/setup$$
48 versionofs=
49 version="$(ddq if=$1 bs=1 skip=$((0x200+$(get 0x20E $1))) | strings | sed q)"
50 if grep --help 2>&1 | grep -q byte-offset; then
51 versionofs=$(grep -obaF "$version" /tmp/setup$$ | sed 's/:.*//')
52 fi
53 if [ -z "$versionofs" ]; then
54 versionofs=$(stat -c %s /tmp/setup$$)
55 echo -en "$version\0" >> /tmp/setup$$
56 fi
57 store 0x20E $(($versionofs-512)) /tmp/setup$$
59 helpersz=0
60 [ -n "$2" ] && helpersz=$(stat -Lc %s "$2")
61 newsetupsz=$((($(stat -c %s /tmp/setup$$)+$helpersz-1)/512))
62 [ $newsetupsz -lt 4 ] && newsetupsz=4
63 store 0x1F1 $newsetupsz /tmp/setup$$ 1
65 if [ $newsetupsz -lt $setupsz ]; then
66 ddq of=/tmp/setup$$ bs=512 seek=$(($newsetupsz+1)) count=0
67 [ -n "$2" ] && ddq if="$2" bs=1 of=/tmp/setup$$ \
68 seek=$((512 + 512*$newsetupsz - $helpersz))
69 [ -n "$3" ] && [ $(stat -Lc %s "$3") -eq 497 ] &&
70 ddq if="$3" conv=notrunc of=/tmp/setup$$
71 ddq if=$1 bs=512 skip=$((1+$setupsz)) >> /tmp/setup$$
72 cp /tmp/setup$$ $1
73 fi
74 rm -f /tmp/setup$$
76 fi