forked from xiaolu/galaxys2_kernel_repack
-
Notifications
You must be signed in to change notification settings - Fork 1
/
repack.sh
executable file
·622 lines (559 loc) · 22.1 KB
/
repack.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
#!/bin/bash
##############################################################################
# you should point where your cross-compiler is
COMPILER=/home/xiaolu/bin/arm-eabi-4.4.3/bin/arm-eabi-
#COMPILER="e:/tools/cygwin/toolchains/arm-linux-androideabi-4.4.3/bin/arm-linux-androideabi-"
COMPILER_LIB=$(${COMPILER}gcc -print-libgcc-file-name | sed -r 's/\/libgcc.a$//')
##############################################################################
#set -x
trap "cleanup" 2 3 4
srcdir=`dirname $0`
# PLATFORM DETECTION
if [[ "$OSTYPE" =~ ^darwin ]]; then
PLATFORM="darwin"
# Ensure we have gmktemp.
if [ -z `which gmktemp` ]; then
printerr "gmktemp is required, install via 'sudo port install coreutils'" && exit 1
fi
tempdir=$(gmktemp -d /tmp/krepack.XXXX)
# Ensure we have greadlink.
if [ -z `which greadlink` ]; then
printerr "greadlink is required, install via 'sudo port install coreutils'" && exit 1
fi
srcdir=`greadlink -f $srcdir`
# cut needs locale set to avoid "illegal byte sequence" error
export LC_ALL=C
# os x stat uses -f %z to get size
STATSIZE='stat -f %z'
# No arguments to dd.
DDARG=
else
# TODO: defaults to Linux. We should detect other platforms.
PLATFORM="linux"
tempdir=$(mktemp -d /tmp/krepack.XXXX)
srcdir="$(readlink -f $srcdir)"
# standard gnu stat uses -c %s to get size
STATSIZE='stat -c %s'
# dd arguments
DDARG="status=noxfer"
fi
RESOURCES=$srcdir/resources
zImage="$1"
kernel="$tempdir/kernel.image"
test_unzipped_cpio="$tempdir/cpio.image"
head_image="$tempdir/head.image"
tail_image="$tempdir/tail.image"
ramdisk_image="$tempdir/ramdisk.image"
workdir="$(pwd)"
rm -f $workdir/repack.log
exec 2>>$workdir/repack.log
C_H1="\033[1;32m"
C_ERR="\033[1;31m"
C_CLEAR="\033[0;0m"
printhl() {
printf "${C_H1}${1}${C_CLEAR} √\n"
}
printerr() {
printf "${C_ERR}${1}${C_CLEAR} ×\n"
}
cleanup()
{
printf "\nCleaning up... finished.\n"
rm -rf /tmp/krepack.*
exit 0
}
exit_usage() {
printf $C_H1
cat << EOT
$0 $*
Error:Not enough parameters or file not found!
Usage:$0 <zImage> <initramfs> [new_zImage_name] [c_type or payload] [c_type]
zImage = the zImage file (kernel) you wish to repack
initramfs = the initramfs you wish to pack into the zImage(file or directory)
new_zImage = new zImage name
c_type = compression type(gzip lzo lzma xz)
payload = padding payload files to new zImage
Repack zImage,Example:
$0 zImagesys267 initramfs.cpio zImage
Padding sufile to zImage offset=7000000,Example:
$0 zImagesy267 sy267.cpio new_zImage su
how to use sufile:
dd if=/dev/block/mmcblk0p5 of=/system/app/Superuser.apk skip=7026336 seek=0 bs=1 count=196640
dd if=/dev/block/mmcblk0p5 of=/system/bin/su skip=7000000 seek=0 bs=1 count=26336
Use payload "tar.xz" in end of zImage:
$0 zImagesy267 initramfs.cpio new_zImage payload
how to use,pls read initramfs-sample/sbin/script/post-init.sh & recovery.sh
recovery.tar.xz and boot.tar.xz in resources directory,you can customize.
Custom zImage compression type:
$0 zImagesy267 initramfs.cpio new_zImage gzip
or
$0 zImagesy267 initramfs.cpio new_zImage payload gzip
EOT
printf $C_CLEAR
cleanup
}
# find start/end of initramfs in the zImage file
find_start_end()
{
echo "---find_start_end()---" 1>&2
pos1=`grep -P -a -b -m 1 -o '\x1F\x8B\x08' $zImage | \
cut -f 1 -d : | awk '(int($0)<50000){print $0;exit}'`
pos2=`grep -P -a -b -m 1 -o '\x{5D}\x{00}\x..\x{FF}\x{FF}\x{FF}\x{FF}\x{FF}\x{FF}' \
$zImage | cut -f 1 -d : | awk '(int($0)<50000){print $0;exit}'`
pos3=`grep -P -a -b -m 1 -o '\xFD\x37\x7A\x58\x5A' $zImage | \
cut -f 1 -d : | tail -1 | awk '(int($0)<50000){print $0;exit}'`
pos4=`grep -P -a -b -o '\211\114\132' $zImage | \
head -2 |tail -1|cut -f 1 -d : | awk '(int($0)<50000){print $0;exit}'`
zImagesize=$($STATSIZE $zImage)
[ -z $pos1 ] && pos1=$zImagesize
[ -z $pos2 ] && pos2=$zImagesize
[ -z $pos3 ] && pos3=$zImagesize
[ -z $pos4 ] && pos4=$zImagesize
minpos=`echo -e "$pos1\n$pos2\n$pos3\n$pos4" | sort -n | head -1`
#uncompress kernel
if [ $minpos -eq $zImagesize ]; then
printerr "not found kernel from $zImage!"
cleanup
elif [ $minpos -eq $pos1 ]; then
printhl "Extracting gzip'd kernel from $zImage (start = $pos1)"
dd if=$zImage of="$kernel.gz" bs=$pos1 skip=1
gunzip -qf "$kernel.gz"
compress_type="gzip"
elif [ $minpos -eq $pos2 ]; then
printhl "Extracting lzma'd kernel from $zImage (start = $pos2)"
dd if=$zImage of="$kernel.lzma" bs=$pos2 skip=1
#unlzma -qf "$kernel.lzma"
unlzma -dqc $kernel.lzma > $kernel
compress_type="lzma"
elif [ $minpos -eq $pos3 ]; then
printhl "Extracting xz'd kernel from $zImage (start = $pos3)"
dd status=noxfer if=$zImage bs=$pos3 skip=1 | unxz -qf > $kernel
compress_type="xz"
elif [ $minpos -eq $pos4 ]; then
printhl "Extracting lzo'd kernel from $zImage (start = $pos4)"
dd if=$zImage of="$kernel.lzo" bs=$pos4 skip=1
lzop -d "$kernel.lzo"
compress_type="lzo"
fi
[ $onlypatch ] && return
#========================================================
# Determine cpio compression type:
#========================================================
for x in none gzip bzip lzma lzop; do
case $x in
bzip)
csig='\x{31}\x{41}\x{59}\x{26}\x{53}\x{59}'
ucmd='bunzip2 -q'
fext='.bz2'
;;
gzip)
csig='\x1F\x8B\x08'
ucmd='gunzip -q'
fext='.gz'
;;
lzma)
csig='\x{5D}\x{00}\x..\x{FF}\x{FF}\x{FF}\x{FF}\x{FF}\x{FF}'
ucmd='unlzma -q'
fext='.lzma'
;;
lzop)
csig='\211\114\132'
ucmd='lzop -d'
fext='.lzo'
;;
none)
csig='070701'
ucmd=
fext=
;;
esac
#========================================================================
# Search for compressed cpio archive
#========================================================================
search=$(grep -P -a -b -m 1 -o $csig $kernel | cut -f 1 -d : | head -1)
pos=${search:-0}
if [ ${pos} -gt 0 ]; then
if [ ${pos} -le ${cpio_compressed_start:-0} ] || [ -z $cpio_compressed_start ];then
cpio_compressed_start=$pos
compression_name=$x
compression_signature=$csig
uncompress_cmd=$ucmd
file_ext=$fext
#break
fi
fi
done
#uncompress cpio,find cpio start and end offset
[ $compression_name = "bzip" ] && cpio_compressed_start=$((cpio_compressed_start - 4))
start=$cpio_compressed_start
dd if=$kernel of=$test_unzipped_cpio bs=$cpio_compressed_start skip=1
if [ ! $compression_name = "none" ]; then
printhl "CPIO compression type detected = $compression_name | offset = $cpio_compressed_start."
end_zero='[\x01-\xff]\x00{8}'
#end_zero='\x00{16}[\x01-\xff]'
end=`grep -P -a -b -m 1 -o $end_zero $test_unzipped_cpio | cut -f 1 -d : | head -1`
#[ $end ] && end=$((end + 16))
[ $end ] && end=$((end + 2))
#end=$((end - end%16))
cpio_compress_type=$compression_name
else
printhl "Non-compressed CPIO image from kernel image (offset = $cpio_compressed_start)."
start_zero='0707010{39}10{55}B0{8}TRAILER!!!'
end1=`grep -P -a -b -m 1 -o $start_zero $test_unzipped_cpio | head -1 | cut -f 1 -d :`
end1=$((end1 + 120))
dd if=$test_unzipped_cpio of=$test_unzipped_cpio.tmp bs=$end1 skip=1
end_zero='\x00{4}[\x01-\xff]'
end2=`grep -P -a -b -m 1 -o $end_zero "$test_unzipped_cpio.tmp" | cut -f 1 -d : | head -1`
[ $end2 ] && end2=$((end2 + 4))
end=$((end1 + end2))
end=$((end - end%16))
cpio_compress_type="gzip"
#[ $compress_type = "lzo" ] && cpio_compress_type="lzop"
fi
}
#Calculation of the size of a Image file,hexadecimal high-low turn
function size_append()
{
echo "---size_append()---" 1>&2
fsize=$($STATSIZE $1);
ch_a=($(printf "%08x\n" $fsize | sed 's/\(..\)/\1 /g'))
for ch in ${ch_a[3]} ${ch_a[2]} ${ch_a[1]} ${ch_a[0]};
do
printf '%c%03o' '\\' $((0x$ch))
done
}
#Calculation file size, 512 bytes integer times
function count512()
{
echo "---count512()---" 1>&2
fsize=$($STATSIZE $1);
if [ $((fsize%512)) -ne 0 ]; then
fsize=$((fsize/512+1))
else
fsize=$((fsize/512))
fi
printf $fsize
}
#use 00 fill to 512 bytes integer times
function append512()
{
echo "---append512()---" 1>&2
dd if=$1 of=$2 bs=512 count=$3 conv=sync
}
function mkbootoffset()
{
echo "---mkbootoffset()---" 1>&2
boot_offset=$(count512 $2)
append512 $2 $tempdir/zImage512 $boot_offset
boot_offset=$((boot_offset+1))
boot_len=$(count512 $3)
boot512=$3
if [ $4 ]; then
recovery_offset=$((boot_offset+boot_len))
recovery_len=$(count512 $4)
append512 $4 $tempdir/recovery512 $recovery_len
recovery_str="recovery_offset=$recovery_offset;recovery_len=$recovery_len;"
recovery512=$tempdir/recovery512
append512 $3 $tempdir/boot512 $boot_len
boot512=$tempdir/boot512
fi
printf "\n\nBOOT_IMAGE_OFFSETS\n" > $tempdir/BOOT_IMAGE_OFFSETS
printf "boot_offset=$boot_offset;boot_len=$boot_len;$recovery_str\n\n" >> $tempdir/BOOT_IMAGE_OFFSETS
append512 $tempdir/BOOT_IMAGE_OFFSETS $tempdir/BOOT_IMAGE_OFFSETS512 1
cat $tempdir/zImage512 $tempdir/BOOT_IMAGE_OFFSETS512 $boot512 $recovery512 > $1
}
MAKE_FIPS_BINARY()
{
echo "---MAKE_FIPS_BINARY()---" 1>&2
printhl "MAKE_FIPS for zImage."
openssl dgst -sha256 -hmac 12345678 -binary -out \
$1.hmac $1
cat $1 $1.hmac > $1.digest
cp -f $1.digest $1
rm -f $1.digest $1.hmac
}
mkpayload()
{
echo "---mkpayload()---" 1>&2
printhl "Make payload file(boot.tar.xz|recovery.tar.xz) from $PAYLOAD_DIR."
cd $tempdir/resources_tmp
rm -f boot.tar.xz recovery.tar.xz
if [ -d $1/boot ]; then
cd $1/boot
#fakeroot tar -Jcf $tempdir/resources_tmp/boot.tar.xz *
tar --owner=0 --group=0 -acf $tempdir/resources_tmp/boot.tar.xz *
else
touch $tempdir/resources_tmp/boot.tar.xz
fi
cd $tempdir/resources_tmp
if [ -d $1/recovery ]; then
cd $1/recovery
#fakeroot tar -Jcf $tempdir/resources_tmp/recovery.tar.xz *
tar --owner=0 --group=0 -acf $tempdir/resources_tmp/recovery.tar.xz *
else
touch $tempdir/resources_tmp/recovery.tar.xz
fi
cd $tempdir/resources_tmp
}
CHECK_MMC_CAP_ERASE()
{
echo "---CHECK_MMC_CAP_ERASE()---" 1>&2
printhl "Check MMC_CAP_ERASE instruction:"
printhl " $(grep -a -o 'Linux version.*\..*\..*:..:.*' $1 | head -n 1 | sed 's/) (/)\n (/g')"
bad_code_pattern="\x80...\x5C...\x06...\x88...\x60...\x00...\x30...\x01...\x6C...\x09...\x88.......\x64...\x28..."
count_bad=$(grep -P -a -b -o $bad_code_pattern $1 | wc -l)
pos_bad=$(grep -P -a -b -o $bad_code_pattern $1 | head -n 1 | cut -f 1 -d :)
[ "$count_bad" -gt 0 ] && \
printerr " $count_bad occurrences of the bad code signature."
# Detect occurrences of the GOOD code pattern
good_code_pattern="\x06...\x60...\x00...\x30...\x88...\x6C.......\x64...\x09...\x88...\x28...\x24..."
count_good=$(grep -P -a -b -o $good_code_pattern $1 | wc -l)
if [ "$count_good" -eq 0 ]; then
good_code_pattern="\x80...\x5C...\x06...\x88...\x60...\x00...\x30...\x00...\x6C...\x09...\x88.......\x64...\x28..."
count_good=$(grep -P -a -b -o $good_code_pattern $1 | wc -l)
[ "$count_good" -eq 1 ] && patched=1
fi
[ "$count_good" -gt 0 ] && \
printhl " $count_good occurrences of the good code signature."
# Print conclusions
if [ $count_bad -eq 0 -a $count_good -eq 1 ]; then
if [ "$patched" -eq 1 ]; then
printhl " The kernel has been patched by this method(MMC_CAP_ERASE disabled)."
else
printhl " The kernel is safe(MMC_CAP_ERASE disabled)."
fi
elif [ $count_bad -eq 1 -a $count_good -eq 0 ]; then
pos_bad=$((pos_bad + 28))
#echo $pos_bad
pos_bad_hex=0x`printf %.8x $pos_bad`
printerr " Found unsafe instruction at offset $pos_bad($pos_bad_hex)"
if [ -z $onlypatch ]; then
printf " Do you want to patch kernel?(N/y)"
read reply leftover
else
reply="y"
fi
case $reply in
y* | Y*)
#patch kernel
printhl " Patching kernel..."
dd if=/dev/zero of=$1 bs=1 count=1 seek=$pos_bad conv=notrunc
printhl " Done.";;
*)
printerr " not patch.";;
esac
else
printhl " Nothing found."
fi
}
function makeImage()
{
echo "---makeImage()---" 1>&2
count=$end
printhl "CPIO image MAX size:$count"
headcount=$((end + start))
printhl "Head count:$headcount"
if [ $count -lt 0 ]; then
printerr "Could not correctly determine the start/end positions of the CPIO!"
cleanup
fi
# Check the Image's size
filesize=$($STATSIZE $kernel)
# Split the Image #1 -> head.img
printhl "Making head.img ( from 0 ~ $start )"
dd if=$kernel bs=$start count=1 of=$head_image
# Split the Image #2 -> tail.img
printhl "Making a tail.img ( from $headcount ~ $filesize )"
dd if=$kernel bs=$headcount skip=1 of=$tail_image
toobig="TRUE"
for method in "cat" "$cpio_compress_type -f9"; do
cat $new_ramdisk | $method - > $ramdisk_image
ramdsize=$($STATSIZE $ramdisk_image)
printhl "Current ramdsize using $method : $ramdsize with required size : $count bytes"
if [ $ramdsize -le $count ]; then
printhl "$method accepted!"
toobig="FALSE"
break;
fi
done
if [ "$toobig" == "TRUE" ]; then
printerr "New ramdisk is still too big. Repack failed. $ramdsize > $count"
printhl "Pls try to use payload method."
cleanup
fi
#Merge head.img + ramdisk
cat $head_image $ramdisk_image > $tempdir/franken.img
franksize=$($STATSIZE -c "%s" $tempdir/franken.img)
#Merge head.img + ramdisk + padding + tail
if [ $franksize -lt $headcount ]; then
printhl "Merging [head+ramdisk] + padding + tail"
tempnum=$((headcount - franksize))
dd $DDARG if=/dev/zero bs=$tempnum count=1 of=$tempdir/padding
cat $tempdir/padding $tail_image > $tempdir/newtail.img
cat $tempdir/franken.img $tempdir/newtail.img > $tempdir/new_Image
elif [ $franksize -eq $headcount ]; then
printhl "Merging [head+ramdisk] + tail"
cat $tempdir/franken.img $tail_image > $tempdir/new_Image
else
printerr "Combined zImage is too large - original end is $end and new end is $franksize"
cleanup
fi
}
###############################################################################
#
# code begins
#
###############################################################################
printhl "---------------------------kernel repacker for i9100---------------------------"
if [ ! -e ${COMPILER}gcc ] || [ ! -e $COMPILER_LIB ]; then
printerr "compiler not found!";
cleanup
fi
if [ ! -f $1 ] || [ -z $2 ] || ([ $2 != "patch" ] && [ ! -e $2 ]); then
exit_usage $*
fi
[ $2 == "patch" ] && onlypatch=1
if [ -z $3 ]; then
new_zImage_name="new_zImage"
else
new_zImage_name=$3
fi
new_zImage_name=$(readlink -m $new_zImage_name)
find_start_end
CHECK_MMC_CAP_ERASE $kernel
#cleanup
if [ -d $2 ]; then
printhl "make initramfs.cpio"
#mkbootfs $2 > $tempdir/initramfs.cpio
cd $2
#find . | sed 's/\.\///g' | cpio -R 0:0 -H newc -o > $tempdir/initramfs.cpio
find . | sed 's/\.\///g' | grep -v -E "\.(payload|git)" | cpio -R 0:0 -H newc -o > $tempdir/initramfs.cpio
cd $workdir
elif [ -f $2 ]; then
cp -rf $2 $tempdir/initramfs.cpio
fi
new_ramdisk=$tempdir/initramfs.cpio
#============================================
# rebuild zImage
#============================================
printhl "Now we are rebuilding the zImage:"
m=$(echo "$4" | tr '[A-Z]' '[a-z]')
if [ -z $5 ]; then
#[[ "${m/gzip/}" != "$m" ]] && compress_type="gzip"
[[ "$m" =~ ^gzip ]] && compress_type="gzip"
[[ "$m" =~ ^lzo ]] && compress_type="lzo"
[[ "$m" =~ ^lzma ]] && compress_type="lzma"
[[ "$m" =~ ^xz ]] && compress_type="xz"
else
compress_type=$5
fi
cp -rf $RESOURCES $tempdir/resources_tmp
if([ ! -d "$PAYLOAD_DIR" ] || [ "$PAYLOAD_DIR" == "" ]); then
PAYLOAD_DIR=$(readlink -f $2)
if ([ -d "$PAYLOAD_DIR/.payload/boot" ] || [ -d "PAYLOAD_DIR/.payload/recovery" ]); then
PAYLOAD_DIR="$PAYLOAD_DIR/.payload"
else
PAYLOAD_DIR=$RESOURCES
fi
fi
if [ "$RESOURCES" != "$PAYLOAD_DIR" ]; then
rm -rf $tempdir/resources_tmp/payload
cp -rf "$PAYLOAD_DIR" $tempdir/resources_tmp/payload
fi
cd $tempdir/resources_tmp
cp -f $kernel arch/arm/boot/Image
if [ -z $onlypatch ]; then
makeImage
cp -f $tempdir/new_Image arch/arm/boot/Image
fi
cp -f include/generated/autoconf.$compress_type.h include/generated/autoconf.h
NOSTDINC_FLAGS="-nostdinc -isystem $COMPILER_LIB/include -Iarch/arm/include \
-Iarch/arm/include/generated -Iinclude \
-include include/generated/autoconf.h -D__KERNEL__ -mlittle-endian \
-Iarch/arm/mach-exynos/include -Iarch/arm/plat-s5p/include -Iarch/arm/plat-samsung/include"
KBUILD_CFLAGS="-Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
-fno-strict-aliasing -fno-common \
-Werror-implicit-function-declaration \
-Wno-format-security \
-fno-delete-null-pointer-checks"
CFLAGS_ABI="-mabi=aapcs-linux -mno-thumb-interwork -D__LINUX_ARM_ARCH__=7 -march=armv7-a"
#for Sourcery_G++_Lite
#[ "${COMPILER_LIB/Sourcery/}" != "$COMPILER_LIB" ] && KBUILD_CFLAGS="$KBUILD_CFLAGS -mno-unaligned-access"
#echo $KBUILD_CFLAGS
#1. Image -> piggy.*
printhl " Image ---> piggy.$compress_type"
llsl=""
if [ $compress_type = "gzip" ]; then
cat arch/arm/boot/Image | gzip -n -f -9 > arch/arm/boot/compressed/piggy.gzip
elif [ $compress_type = "lzma" ]; then
(cat arch/arm/boot/Image | lzma -9 && printf $(size_append arch/arm/boot/Image)) \
> arch/arm/boot/compressed/piggy.lzma
elif [ $compress_type = "xz" ]; then
llsl="arch/arm/boot/compressed/ashldi3.o"
compress_type="xzkern"
(cat arch/arm/boot/Image | xz --check=crc32 --arm --lzma2=,dict=32MiB && \
printf $(size_append arch/arm/boot/Image)) > arch/arm/boot/compressed/piggy.xzkern
printhl " Compiling ashldi3.o"
${COMPILER}gcc -Wp,-MD,arch/arm/boot/compressed/.ashldi3.o.d $NOSTDINC_FLAGS \
-D__ASSEMBLY__ $CFLAGS_ABI -include asm/unified.h -msoft-float -gdwarf-2 \
-Wa,-march=all -c -o arch/arm/boot/compressed/ashldi3.o arch/arm/lib/ashldi3.S
elif [ $compress_type = "lzo" ]; then
(cat arch/arm/boot/Image | lzop -9 && printf $(size_append arch/arm/boot/Image)) \
> arch/arm/boot/compressed/piggy.lzo
fi
#2. piggy.* -> piggy.*.o
printhl " piggy.$compress_type ---> piggy.$compress_type.o"
${COMPILER}gcc -Wp,-MD,arch/arm/boot/compressed/.piggy.$compress_type.o.d $NOSTDINC_FLAGS -D__ASSEMBLY__ $CFLAGS_ABI -include asm/unified.h -msoft-float -gdwarf-2 -Wa,-march=all -c -o arch/arm/boot/compressed/piggy.$compress_type.o arch/arm/boot/compressed/piggy.$compress_type.S
#3. head.o
printhl " Compiling head.o"
${COMPILER}gcc -Wp,-MD,arch/arm/boot/compressed/.head.o.d $NOSTDINC_FLAGS -D__ASSEMBLY__ $CFLAGS_ABI -include asm/unified.h -msoft-float -gdwarf-2 -Wa,-march=all -DTEXT_OFFSET=0x00008000 -DFIPS_KERNEL_RAM_BASE=0x40008000 -c -o arch/arm/boot/compressed/head.o arch/arm/boot/compressed/head.S
#4. misc.o
printhl " Compiling misc.o"
${COMPILER}gcc -Wp,-MD,arch/arm/boot/compressed/.misc.o.d $NOSTDINC_FLAGS $KBUILD_CFLAGS -O2 -fdiagnostics-show-option -Werror -Wno-error=unused-function -Wno-error=unused-variable -Wno-error=unused-value -Wno-error=unused-label -marm -fno-dwarf2-cfi-asm -fno-omit-frame-pointer -mapcs -mno-sched-prolog $CFLAGS_ABI -msoft-float -Uarm -Wframe-larger-than=1024 -fno-stack-protector -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -fpic -fno-builtin $CFLAGS_KERNEL -D"KBUILD_STR(s)=\#s" -D"KBUILD_BASENAME=KBUILD_STR(misc)" -D"KBUILD_MODNAME=KBUILD_STR(misc)" -c -o arch/arm/boot/compressed/misc.o arch/arm/boot/compressed/misc.c
#5. decompress.o
printhl " Compiling decompress.o"
${COMPILER}gcc -Wp,-MD,arch/arm/boot/compressed/.decompress.o.d $NOSTDINC_FLAGS $KBUILD_CFLAGS -O2 -fdiagnostics-show-option -Werror -Wno-error=unused-function -Wno-error=unused-variable -Wno-unused-but-set-variable -Wno-error=unused-value -Wno-error=unused-label -marm -fno-dwarf2-cfi-asm -fno-omit-frame-pointer -mapcs -mno-sched-prolog $CFLAGS_ABI -msoft-float -Uarm -Wframe-larger-than=1024 -fno-stack-protector -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -fpic -fno-builtin $CFLAGS_KERNEL -D"KBUILD_STR(s)=\#s" -D"KBUILD_BASENAME=KBUILD_STR(decompress)" -D"KBUILD_MODNAME=KBUILD_STR(decompress)" -c -o arch/arm/boot/compressed/decompress.o arch/arm/boot/compressed/decompress.c
#6. lib1funcs.o
printhl " Compiling lib1funcs.o"
${COMPILER}gcc -Wp,-MD,arch/arm/boot/compressed/.lib1funcs.o.d $NOSTDINC_FLAGS -D__ASSEMBLY__ $CFLAGS_ABI -include asm/unified.h -msoft-float -gdwarf-2 -Wa,-march=all -c -o arch/arm/boot/compressed/lib1funcs.o arch/arm/lib/lib1funcs.S
#7. vmlinux.lds
printhl " Create vmlinux.lds"
sed "s/TEXT_START/0/;s/BSS_START/ALIGN(8)/" < arch/arm/boot/compressed/vmlinux.lds.in > arch/arm/boot/compressed/vmlinux.lds
#8. head.o + misc.o + piggy.*.o --> vmlinux
[ $llsl ] && ashldi3="ashldi3.o"
printhl " head.o misc.o piggy.$compress_type.o decompress.o lib1funcs.o $ashldi3 -> vmlinux"
${COMPILER}ld -EL --defsym zreladdr=0x40008000 -p --no-undefined -X -T arch/arm/boot/compressed/vmlinux.lds arch/arm/boot/compressed/head.o arch/arm/boot/compressed/piggy.$compress_type.o arch/arm/boot/compressed/misc.o arch/arm/boot/compressed/decompress.o arch/arm/boot/compressed/lib1funcs.o $llsl -o arch/arm/boot/compressed/vmlinux
#9. vmlinux -> zImage
printhl " vmlinux ---> zImage"
${COMPILER}objcopy -O binary -R .comment -S arch/arm/boot/compressed/vmlinux arch/arm/boot/zImage
newzImagesize=$($STATSIZE arch/arm/boot/zImage)
printhl " Compiled new zImage size:$newzImagesize"
#MAKE_FIPS
MAKE_FIPS_BINARY arch/arm/boot/zImage
rm -f $new_zImage_name
if [[ "$m" =~ ^payload ]]; then
mkpayload ./payload
printhl "Padding payload files to $(basename $new_zImage_name)."
if [[ "$m" =~ ^payloadb ]]; then
mkbootoffset new_zImage arch/arm/boot/zImage boot.tar.xz
else
mkbootoffset new_zImage arch/arm/boot/zImage boot.tar.xz recovery.tar.xz
fi
newzImagesize=$($STATSIZE new_zImage)
printhl "Now zImage size:$newzImagesize bytes."
[ $newzImagesize -gt 8388608 ] && printerr "zImage too big..." && cleanup
printhl "Padding new zImage to 8M."
dd if=new_zImage of=$new_zImage_name bs=8M conv=sync
elif [[ "$m" =~ ^su ]]; then
printhl "Padding sufiles to $new_zImage_name."
dd if=arch/arm/boot/zImage of=$new_zImage_name bs=8M conv=sync
dd if=sufile.pad of=$new_zImage_name bs=1 count=222976 seek=7000000 conv=notrunc
elif [[ "$m" =~ ^pad ]]; then
printhl "Padding new zImage to 8M bytes."
dd if=arch/arm/boot/zImage of=$new_zImage_name bs=8M conv=sync
else
cp -f arch/arm/boot/zImage $new_zImage_name
fi
printhl "$(basename $new_zImage_name) has been created."
cd $workdir
cleanup