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

Up linux 2.6.20 (avoid 386 & 486 problems)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Jul 14 14:20:00 2021 +0000 (2021-07-14)
parents 3de5e6325aab
children d5c772484b59
line source
1 #!/bin/sh
3 if [ "$1" = "--build" ]; then #install-begin
4 while read type pack args; do
5 grep -q "#define COMPRESSION.*$type" unpacklz4.S || continue
6 sed -i "s/COMPRESSOR/$pack/;s/COMPRESSION/$pack $args/" $0
7 done <<EOT
8 LZMA lzma -si -so $(sed '/^#define PROP_/!d;s|.*_|-|;s| *||;y/PBLPC/pblpc/' unlzma.S) | ddq bs=13 skip=1
9 LZSA2 lzsa -r -f 2
10 LZSA1 lzsa -r -f 1
11 LZ4 lz4 -l -12 | ddq bs=4 skip=1
12 EOT
13 uuencode -m - < unpacklz4.bin | sed -e '/^unpacklz4\.bin$/r/dev/stdin' \
14 -e '/^unpacklz4\.bin$/d' -i $0
15 cat helper.bin 2>/dev/null | uuencode -m - | sed -e \
16 '/^helper\.bin$/r/dev/stdin' -e '/^helper\.bin$/d' -i $0
17 sed '/install-begin$/,/install-end$/d' -i $0
18 exit
19 fi #install-end
20 ddq()
21 {
22 dd "$@" 2> /dev/null
23 }
25 word()
26 {
27 n=$1; for i in $(seq 1 1 ${2:-2}); do
28 printf '\\\\x%02X' $(($n & 255))
29 n=$(($n >> 8))
30 done | xargs echo -en
31 }
33 store()
34 {
35 word $2 "$4" | ddq bs=1 conv=notrunc of="$3" seek=$(($1))
36 }
38 get()
39 {
40 echo $(od -j $(($1)) -N ${3:-2} -t u${3:-2} -An "$2")
41 }
43 helper()
44 {
45 uudecode << EOT
46 helper.bin
47 EOT
48 }
50 [ ! -s "$1" ] && echo "Usage: $0 bzImage" && exit 1
52 if which COMPRESSOR > /dev/null ; then
54 # boot + head param
55 param=$((514+$(get 0x201 $1 1)))
56 ddq if=$1 bs=1 count=$param > /tmp/setup$$
58 # unlz4 + data
59 uudecode >> /tmp/setup$$ << EOT
60 unpacklz4.bin
61 EOT
62 setupsz=$(get 0x1F1 $1 1)
63 ddq if=$1 bs=1 skip=$param count=$(($setupsz*512-$param+512)) | \
64 COMPRESSION >> /tmp/setup$$
66 # version string
67 word $(get 0x20E $1) >> /tmp/setup$$
68 word $setupsz 1 >> /tmp/setup$$
69 setupend=$(stat -Lc %s "/tmp/setup$$")
70 versionofs=
71 version="$(ddq if=$1 bs=1 skip=$((0x200+$(get 0x20E $1))) | strings | sed q)"
72 if grep --help 2>&1 | grep -q byte-offset; then
73 versionofs=$(grep -obaF "$version" /tmp/setup$$ | sed 's/:.*//')
74 fi
75 if [ -z "$versionofs" ]; then
76 versionofs=$(stat -c %s /tmp/setup$$)
77 echo -en "$version\0" >> /tmp/setup$$
78 fi
79 store 0x20E $(($versionofs-512)) /tmp/setup$$
81 helpersz=$(helper | wc -c)
82 newsetupsz=$((($(stat -c %s /tmp/setup$$)+$helpersz-1)/512))
83 [ $newsetupsz -lt 4 ] && newsetupsz=4
85 if [ $newsetupsz -lt $setupsz ]; then
86 while [ $(($setupend + $helpersz)) -gt $((512 + 512*$newsetupsz)) ]; do
87 newsetupsz=$(($newsetupsz+1))
88 done
89 # ddq of=/tmp/setup$$ bs=512 seek=$(($newsetupsz+1)) count=0
90 store 0x1F1 $newsetupsz /tmp/setup$$ 1
91 helper | ddq bs=1 of=/tmp/setup$$ \
92 seek=$((512 + 512*$newsetupsz - $helpersz))
93 ddq if=$1 bs=512 skip=$((1+$setupsz)) >> /tmp/setup$$
94 cp /tmp/setup$$ $1
95 fi
96 rm -f /tmp/setup$$
98 fi