Updated: expand initramfs ramdisc from zImage kernel, supports gzip, lzma, bzip2 (?) - Galaxy Tab Android Development

If you are interested in building your own kernels (from the Samsung-released open-source code, or any other source), you may need to extract initramfs ramdiscs from existing kernels.
There is a well-known script to achieve that goal, but it only supports uncompressed and gzip'ed kernels, and it doesn't unpack the CPIO archive for further inspection of the actual initramfs "source code" (the output trace is also not easy to debug when working with "weird" zImages). The original script is explained in the XDA wiki: http://forum.xda-developers.com/wiki/index.php?title=Extract_initramfs_from_zImage.
For my personal convenience, I tweaked the original bash script so I thought I'd share it with the XDA devs. I added support for lzma-compressed initramfs ramdiscs (thanks to koxudaxi for reminding me of the lzma "magic string"), please let me know if you know the "magic string" for bzip2 archives (EDIT: "0x314159265359" 6 bytes "start of block", 4 bytes header at the beginning...experimental untested support is now available in the script below).
Note that the latest Samfirmware ROMs include encrypted boot.bin and Sbl.bin bootloaders, but I'm not sure how the zImage kernels are encoded...so this script may not work.
Also note that zImage files patched with z4mod require further decoding work, see the XDA wiki page mentioned above for instructions.
Code:
#!/bin/bash
zImage=$1
read -rp "Enter any text to skip extraction (assumes /tmp/kernel2.img already exists): " input
if [ ${input}" " = " " ]; then
echo "==> deleting /tmp/kernel1.img"
rm /tmp/kernel1.img
echo "==> deleting /tmp/kernel2.img"
rm /tmp/kernel2.img
echo "==> searching for gzip header in $zImage"
skip=`grep -P -a -b -m 1 --only-matching $'\x1F\x8B\x08' $zImage | cut -f 1 -d :`
echo "==> found gzip header at $skip"
echo "==> unzipping $zImage to /tmp/kernel1.img"
dd if=$zImage bs=1 skip=$skip | gunzip > /tmp/kernel1.img
echo "==> searching for gzip header in /tmp/kernel1.img"
poszip=`grep -P -a -b -m 1 --only-matching $'\x1F\x8B\x08' /tmp/kernel1.img | cut -f 1 -d :`
if [ ! $poszip = "" ]; then
echo "==> gzip header at $poszip in /tmp/kernel1.img"
echo "==> extracting /tmp/kernel2.img from /tmp/kernel1.img using gunzip"
dd if=/tmp/kernel1.img bs=1 skip=$poszip | gunzip > /tmp/kernel2.img
else
echo "==> no gzip header in /tmp/kernel1.img"
echo "==> searching for lzma header in /tmp/kernel1.img"
poslzma=`grep -P -a -b -m 1 --only-matching '\x{5D}\x{00}\x..\x{FF}\x{FF}\x{FF}\x{FF}\x{FF}\x{FF}' /tmp/kernel1.img | cut -f 1 -d :`
if [ ! $poslzma = "" ]; then
echo "==> lzma header at $poslzma in /tmp/kernel1.img"
echo "==> extracting /tmp/kernel2.img from /tmp/kernel1.img using lzma"
dd if=/tmp/kernel1.img bs=1 skip=$poslzma | unlzma > /tmp/kernel2.img
else
echo "==> no lzma header in /tmp/kernel1.img"
echo "==> searching for bzip2 header in /tmp/kernel1.img"
posbzip2=`grep -P -a -b -m 1 --only-matching $'\x{42}\x{5A}\x{68}\x{39}\x{31}\x{41}\x{59}\x{26}\ x{53}\x{59}' /tmp/kernel1.img | cut -f 1 -d :`
if [ ! $posbzip2 = "" ]; then
echo "==> bzip2 header at $posbzip2 in /tmp/kernel1.img"
posbzip2=$((posbzip2 - 4))
echo "==> adjusted bzip2 header with -4 bytes offset: $posbzip2"
echo "==> extracting /tmp/kernel2.img from /tmp/kernel1.img using bzip2"
dd if=/tmp/kernel1.img bs=1 skip=$posbzip2 | bunzip2 > /tmp/kernel2.img
else
echo "==> no bzip2 header in /tmp/kernel1.img"
echo "==> assuming no compression for /tmp/kernel1.img, copying to /tmp/kernel2.img"
cp /tmp/kernel1.img /tmp/kernel2.img
fi
fi
fi
fi
# '070701' == $'\x30\x37\x30' == '\x{30}\x{37}\x{30}'
echo "==> searching for cpio header in /tmp/kernel2.img"
start=`grep -a -b -m 1 --only-matching '070701' /tmp/kernel2.img | head -1 | cut -f 1 -d :`
echo "==> cpio header at $start in /tmp/kernel2.img"
echo "==> searching for cpio footer in /tmp/kernel2.img"
end=`grep -a -b -m 1 --only-matching 'TRAILER!!!' /tmp/kernel2.img | head -1 | cut -f 1 -d :`
echo "==> cpio footer at $end in /tmp/kernel2.img"
# 14 bytes = length of "TRAILER!!!" (zero-terminated string) + padding => fixes premature end of file warning in CPIO
end=$((end + 14))
echo "==> adjusted cpio footer with 14 bytes offset: $end"
count=$((end - start))
echo "==> cpio size is $count bytes ($end - $start)"
if (($count < 0)); then
echo "==> error in cpio positions, aborting"
exit
fi
cpio_file="initramfs.cpio"
cpio_dir=`echo "${cpio_file}.expanded"`
cpio_ls=`echo "${cpio_file}.ls"`
echo "==> deleting ${zImage}_${cpio_file}"
rm ${zImage}_${cpio_file}
echo "==> deleting ${zImage}_${cpio_dir}"
rm -r ${zImage}_${cpio_dir}
echo "==> deleting ${zImage}_${cpio_ls}"
rm -r ${zImage}_${cpio_ls}
echo "==> extracting initramfs ramdisc from /tmp/kernel2.img to ${zImage}_${cpio_file}"
dd if=/tmp/kernel2.img bs=1 skip=$start count=$count > ${zImage}_${cpio_file}
echo "==> expanding ${zImage}_${cpio_file} into ${zImage}_${cpio_dir} directory"
mkdir ${zImage}_${cpio_dir}
curdir=`pwd`
(cd ${zImage}_${cpio_dir} && cpio --quiet -id --no-absolute-filenames < ${curdir}/${zImage}_${cpio_file})
echo "==> generating ls-like file list in ${zImage}_${cpio_ls}"
cpio --quiet -tvnF ${zImage}_${cpio_file} > ${zImage}_${cpio_ls}
echo "==> DONE."

- heads-up - nice rewrite/cleanup by Mistadman:
https://github.com/mistadman/Extract-Kernel-Initramfs/

Related

[HOW TO]Unpack/Repack initramfs in zImage (update for cygwin)

The latest version:
https://github.com/xiaolu/galaxys2_kernel_repack
update for cygwin
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
I hate GFW
I got a problem after repacked the new zImage.
The original size of zImage is 8MB, but the new zImage is 5MB...
Chenglu said:
Unpack:
Code:
./k-unpack zImagexwki8 initramfs-ki8
[I] Extracting gzip'd kernel image from file: zImagexwki8 (start = 16621)
[I] CPIO compression type detected = none | offset = 163840
[I] Extracting non-compressed CPIO image from kernel image (offset = 163840)
[I] Expanding CPIO archive: initramfs.cpio to initramfs-ki8.
Create newinitramfs.cpio:
Code:
./gen_initramfs.sh -o newinitramfs-ki8.cpio -u 0 -g 0 ./initramfs-ki8
or
Code:
cd initramfs-ki8
find . | cpio -o -H newc > ../newinitramfs-ki8.cpio
Edit k-repack Modified to your cross-compiler:
Code:
COMPILER=/home/xiaolu/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-eabi
COMPILER_LIB=/home/xiaolu/CodeSourcery/Sourcery_G++_Lite/lib/gcc/arm-none-eabi/4.5.2
Rebuild kernel:
Code:
./k-repack zImagexwki8 newinitramfs-ki8.cpio
[I] ---------------------------kernel repacker for i9100---------------------------
[I] Extracting gzip'd kernel from zImagexwki8 (start = 16621)
[I] Non-compressed CPIO image from kernel image (offset = 163840)
[I] CPIO image MAX size:3044984
[I] head count:3208824
[I] Making head.img ( from 0 ~ 163840 )
[I] Making a tail.img ( from 3208824 ~ 13773971 )
[I] Current ramdsize using cat : 3045376 with required size : 3044984
[I] Current ramdsize using gzip -fc : 1888879 with required size : 3044984
[I] gzip -fc accepted!
[I] Merging [head+ramdisk] + padding + tail
[I] Now we are rebuilding the zImage
[I] Image ---> piggy.gzip
[I] piggy.gzip ---> piggy.gzip.o
[I] Compiling head.o
[I] Compiling misc.o
[I] Compiling decompress.o
[I] Compiling lib1funcs.o
[I] Create vmlinux.lds
[I] head.o + misc.o + piggy.gzip.o + decompress.o + lib1funcs.o---> vmlinux
[I] vmlinux ---> zImage
[I] Re-compiled to new_zImage
[I] Cleaning up...
[I] finished...
Resources form GT-I9100_OpenSource_Update2(https://opensource.samsung.com )
initramfs-xwki8-cwm5.0.2.6.zip is modified initramfs for xwki8 stock kernel.
Click to expand...
Click to collapse
You are my hero
Thanks for making it
rock_shen said:
I got a problem after repacked the new zImage.
The original size of zImage is 8MB, but the new zImage is 5MB...
Click to expand...
Click to collapse
No problem,CPIO image is gzipped
rock_shen said:
I got a problem after repacked the new zImage.
The original size of zImage is 8MB, but the new zImage is 5MB...
Click to expand...
Click to collapse
use command Filled to 8387840 bytes
Code:
dd if=new_zImage of=zImage bs=8387840 conv=sync
I have writed a script for easy repacking/unpacking/padding
Code:
#!/bin/sh
REUNPACK=$1
if [ $REUNPACK == repack ]; then
cd initramfs_root
find . | cpio -o -H newc > ../initramfs.cpio
cd ..
./k-repack zImage initramfs.cpio
fi;
if [ $REUNPACK == unpack ]; then
./k-unpack zImage
fi;
if [ $REUNPACK == cpio ]; then
cd initramfs_root
find . | cpio -o -H newc > ../initramfs.cpio
fi;
if [ $REUNPACK == padding ]; then
rm -rf zImage
dd if=new_zImage of=zImage bs=8387840 conv=sync
fi;
if [ $REUNPACK == clean ]; then
rm -rf zImage initramfs_root initramfs.cpio new_zImage
echo "Done!"
fi;
netchip said:
I have writed a script for easy repacking/unpacking/padding
Code:
#!/bin/sh
REUNPACK=$1
if [ $REUNPACK == repack ]; then
cd initramfs_root
find . | cpio -o -H newc > ../initramfs.cpio
cd ..
./k-repack zImage initramfs.cpio
fi;
if [ $REUNPACK == unpack ]; then
./k-unpack zImage
fi;
if [ $REUNPACK == cpio ]; then
cd initramfs_root
find . | cpio -o -H newc > ../initramfs.cpio
fi;
if [ $REUNPACK == padding ]; then
rm -rf zImage
dd if=new_zImage of=zImage bs=8387840 conv=sync
fi;
if [ $REUNPACK == clean ]; then
rm -rf zImage initramfs_root initramfs.cpio new_zImage
echo "Done!"
fi;
Click to expand...
Click to collapse
good work
Chenglu said:
I hate GFW
Click to expand...
Click to collapse
haha
me too
guaiwujia said:
haha
me too
Click to expand...
Click to collapse
hiahia
nice scripttl there. makes it easier for devs.
Sent from my GT-I9100 using xda premium
update to v3
Chenglu said:
I hate GFW
Click to expand...
Click to collapse
me too!~
thx
.......
What is GFW?
Sent from my GT-I9100
The Great Fire Wall of China
Chenglu said:
The Great Fire Wall of China
Click to expand...
Click to collapse
I dont like that too xD
black-snowflake said:
me too!~
Click to expand...
Click to collapse
Foreigners don't know what’s GWF you said here, but I think you know who I am!
I'm having a problem. Whenever I try to repack a kernel, it says the ramdisk size is too big. It also says realpath command isn't found on line 12.
Code:
[email protected]:~/Desktop/Kernel/tools# ./repack zImage newinitramfs.cpio
./repack: line 12: realpath: command not found
[I] ---------------------------kernel repacker for i9100---------------------------
[I] Extracting gzip'd kernel from zImage (start = 16621)
[I] CPIO compression type detected = gzip | offset = 163840
[I] CPIO image MAX size:2860094
[I] Head count:3023934
[I] Making head.img ( from 0 ~ 163840 )
[I] Making a tail.img ( from 3023934 ~ 10612864 )
[I] Current ramdsize using cat : 4573696 with required size : 2860094 bytes
[I] Current ramdsize using gzip -f9 : 2866888 with required size : 2860094 bytes
[E] New ramdisk is still too big. Repack failed. 2866888 > 2860094
Tried both 4.4.1 & 4.5.2 version of G++ Lite, none of them is fixes the problem.
Looks like there's something wrong with gzip..
Help?
Padding big binary files to end of the zImage files.
Example(initramfs-tools-v5 Padding sufiles to zImage files):
How to use:
Code:
busybox dd if=/dev/block/mmcblk0p5 of=/system/app/Superuser.apk skip=7026336 seek=0 bs=1 count=196640
busybox dd if=/dev/block/mmcblk0p5 of=/system/bin/su skip=7000000 seek=0 bs=1 count=26336

[Q] Odexing MIUIv4 or other ICS ROM

hello i trying to ODEX my MIUIv4 (ICS 4.0.4) but i had some troubles:
there is my script for odexing:
Code:
#/sbin/sh
D=/data
E=/sddata
S=/system
SD=/sdcard
bbcmd="busybox"
bbcat="$bbcmd cat"
bbgrep="$bbcmd grep"
bbsed="$bbcmd sed"
SYSTARGET="/system"
OPTTEMP="/tmp"
$bbcmd chmod 777 $OPTTEMP/{busybox,dexopt_wrapper,zip,zipalign}
mount -o rw /system
mount -o rw /data
mount -o rw /cache
local zip="$OPTTEMP/zip"
local zipalign="$OPTTEMP/zipalign"
local dexopt_wrapper="$OPTTEMP/dexopt_wrapper"
local bootclpath="/system/framework/core.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/android.policy.jar:/system/framework/services.jar:/system/framework/apache-xml.jar:/system/framework/filterfw.jar"
# change to system/framework and process EVERY jar IN ORDER OF BOOTCLASSPATH!
cd /system/framework
indir=$(pwd)
for filename in \
core.jar core-junit.jar miui-framework.jar bouncycastle.jar ext.jar framework.jar android.policy.jar services.jar apache-xml.jar filterfw.jar \
am.jar ime.jar android.test.runner.jar input.jar javax.obex.jar monkey.jar pm.jar svc.jar bmgr.jar com.android.location.provider.jar com.android.future.usb.accessory.jar com.google.android.maps.jar com.google.android.media.effects.jar com.google.widevine.software.drm.jar
do
name=${filename%.jar}
$bbcmd cp -f $filename $OPTTEMP/$filename
$dexopt_wrapper $filename $name.odex $bootclpath > /dev/null 2>&1
if [ $? -eq 0 ]
then
$zip -d $filename classes.dex > /dev/null 2>&1
$bbcmd cp -f $name.odex $OPTTEMP/$name.odex
echo "$filename - done."
else
$bbcmd rm *.odex
$bbcmd cp -f $OPTTEMP/*.jar $indir/
echo "Framework file $filename failled. Cannot Complete."
echo "System has been restored."
return 1;
fi
done
$zipalign 4 framework-res.apk framework-res.apk.align > /dev/null 2>&1
$bbcmd mv -f framework-res.apk.align framework-res.apk
$zipalign 4 framework-miui-res.apk framework-miui-res.align > /dev/null 2>&1
$bbcmd mv -f framework-miui-res.align framework-miui-res.apk
cd /system/app
indir=$(pwd)
# Process apks from system/app that are normally odexed
for filename in *.apk
do
name=${filename%.apk}
$dexopt_wrapper $filename $name.odex $bootclpath > /dev/null 2>&1
if [ $? -eq 0 ]
then
$zip -d $filename classes.dex > /dev/null 2>&1
$zipalign 4 $filename $filename.align > /dev/null 2>&1
$bbcmd mv -f $filename.align $filename
echo "$filename - done."
fi
done
$bbcmd find /system/framework -type f -exec chmod 644 {} \;
$bbcmd find /system/app -type f -exec chmod 644 {} \;
[ -d /cache/dalvik-cache ] && $bbcmd rm -rf /cache/dalvik-cache/*
[ -d /data/dalvik-cache ] && $bbcmd rm -rf /data/dalvik-cache/*
return 0;
and i had errors in android.policy, framework, services .odex files

99swap doesnt run from init.d

I am on MIUI ICS v4.
I have 99swap in system/etc/init.d
I have the .swapfile in /scdard/.swapfile
..the problem is.. I have to manualy activate Swapfile everytime I reboot.. why is the script not working.. when I was on MIUI v5 by maxworks as well same like v4.. it used to work correct..
I have given the system.. the etc.. and init.d folder all access. Read.Write.Execute
Below is MIUI v5 Script that used to work when I used that ROM.
#!/system/bin/sh
#Created by neamv for maxworks. All rights reserved
filename=/sdcard/.swapfile
fsize=256
recreate_on_boot=1
#sleep=120
timeout=240
while [ -z "`mount | grep "sdcard0 "`" ]; do
[ $timeout -lt 0 ] && exit 0
timeout=$(($timeout-10))
sleep 10
done
[ -n "`mount | grep "sdcard .*ntfs"`" ] && exit 0
if [ "$recreate_on_boot" == 1 ]; then
dd if=/dev/zero of=$filename"_new" bs=1024 count=$(($fsize*1024)) && mkswap $filename"_new" && mv $filename"_new" $filename
else
[ -f $filename ] && [ `stat -t $filename | awk '{print ($2)}'` -ne $(($fsize*1024*1024)) ] && rm $filename
[ ! -f $filename ] && dd if=/dev/zero of=$filename bs=1024 count=$(($fsize*1024)) && mkswap $filename
fi
swapon $filename
and below now is v4 script that doesn't work
#!/sbin/sh
#Created by neamv for maxworks. All rights reserved
filename=/sdcard/.swapfile
fsize=256
recreate_on_boot=1
timeout=240
while [ -z "`mount | grep "sdcard "`" ]; do
[ $timeout -lt 0 ] && exit 0
timeout=$(($timeout-10))
sleep 10
done
[ -n "`mount | grep "sdcard .*ntfs"`" ] && exit 0
if [ "$recreate_on_boot" == 1 ]; then
dd if=/dev/zero of=$filename"_new" bs=1024 count=$(($fsize*1024)) && mkswap $filename"_new" && mv $filename"_new" $filename
else
[ -f $filename ] && [ `stat -t $filename | awk '{print ($2)}'` -ne $(($fsize*1024*1024)) ] && rm $filename
[ ! -f $filename ] && dd if=/dev/zero of=$filename bs=1024 count=$(($fsize*1024)) && mkswap $filename
fi
swapon $filename
I didn't want to mess my phone.. so I thougt to ask. Plz automate the process of the Swapfile getting loaded after reboot.. it actually should be created on every boot at a different place in the SD-Card.. this is what I read from Maxworks.
Edit.. One more Question.. If I can.. to make my phone fun faster.. how large should I create the .swapfile.. lets say.. 512MB ?? 1 gb ?? and how to set the swappines.. (and no.. I don't want to use Swapper2)
BUMP
Well, it should work, but may be caused by extensive brake swap. Try chaging the swap size
You can edit the file / system/etc/init.d/99swap replacing in fsize 256 to 64 for example.
saqibkhan said:
I am on MIUI ICS v4.
I have 99swap in system/etc/init.d
I have the .swapfile in /scdard/.swapfile
..the problem is.. I have to manualy activate Swapfile everytime I reboot.. why is the script not working.. when I was on MIUI v5 by maxworks as well same like v4.. it used to work correct..
I have given the system.. the etc.. and init.d folder all access. Read.Write.Execute
Below is MIUI v5 Script that used to work when I used that ROM.
#!/system/bin/sh
#Created by neamv for maxworks. All rights reserved
filename=/sdcard/.swapfile
fsize=256
recreate_on_boot=1
#sleep=120
timeout=240
while [ -z "`mount | grep "sdcard0 "`" ]; do
[ $timeout -lt 0 ] && exit 0
timeout=$(($timeout-10))
sleep 10
done
[ -n "`mount | grep "sdcard .*ntfs"`" ] && exit 0
if [ "$recreate_on_boot" == 1 ]; then
dd if=/dev/zero of=$filename"_new" bs=1024 count=$(($fsize*1024)) && mkswap $filename"_new" && mv $filename"_new" $filename
else
[ -f $filename ] && [ `stat -t $filename | awk '{print ($2)}'` -ne $(($fsize*1024*1024)) ] && rm $filename
[ ! -f $filename ] && dd if=/dev/zero of=$filename bs=1024 count=$(($fsize*1024)) && mkswap $filename
fi
swapon $filename
and below now is v4 script that doesn't work
#!/sbin/sh
#Created by neamv for maxworks. All rights reserved
filename=/sdcard/.swapfile
fsize=256
recreate_on_boot=1
timeout=240
while [ -z "`mount | grep "sdcard "`" ]; do
[ $timeout -lt 0 ] && exit 0
timeout=$(($timeout-10))
sleep 10
done
[ -n "`mount | grep "sdcard .*ntfs"`" ] && exit 0
if [ "$recreate_on_boot" == 1 ]; then
dd if=/dev/zero of=$filename"_new" bs=1024 count=$(($fsize*1024)) && mkswap $filename"_new" && mv $filename"_new" $filename
else
[ -f $filename ] && [ `stat -t $filename | awk '{print ($2)}'` -ne $(($fsize*1024*1024)) ] && rm $filename
[ ! -f $filename ] && dd if=/dev/zero of=$filename bs=1024 count=$(($fsize*1024)) && mkswap $filename
fi
swapon $filename
I didn't want to mess my phone.. so I thougt to ask. Plz automate the process of the Swapfile getting loaded after reboot.. it actually should be created on every boot at a different place in the SD-Card.. this is what I read from Maxworks.
Edit.. One more Question.. If I can.. to make my phone fun faster.. how large should I create the .swapfile.. lets say.. 512MB ?? 1 gb ?? and how to set the swappines.. (and no.. I don't want to use Swapper2)
Click to expand...
Click to collapse

[SCRIPT][BACKUP][TOOL]Preserve addon , dpi , Xposed app_process /system files

Hi,
i flash many roms and sometimes after new rom flashed , i see dpi preserved my change before flash, even some rom preserve xposed framework still activated...maybe you have experience with some other backup/restore /system files during flash, maybe have you another idea to preserve some stuff.
For my part, i make a new backuptool.sh and backuptool.functions scripts compiled with some i find over roms i tried....
We have:
save dpi
save xposed framework
save addond
i think in red are the line you can personalize, i hope you know what to do with.
backuptool.sh
Code:
#!/sbin/sh
#
# Backup and restore addon /system files
#
export C=/tmp/backup
export S=/system
[COLOR="Red"]export V=what you want[/COLOR]
persist_props="ro.sf.lcd_density"
sysroot="/system"
saveroot="/tmp/save"
# Preserve DPI
save_props()
{
rm -f "$saveroot/prop"
for prop in $persist_props; do
echo "save_props: $prop"
grep "^$prop=" "$sysroot/build.prop" >> "$saveroot/prop"
done
}
# Restore DPI
restore_props()
{
local sedargs
sedargs="-i"
for prop in $(cat $saveroot/prop); do
echo "restore_props: $prop"
k=$(echo $prop | cut -d'=' -f1)
sedargs="$sedargs s/^$k=.*/$prop/"
done
sed $sedargs "$sysroot/build.prop"
}
# Backup Xposed Framework (bin/app_process)
xposed_backup()
{
if [ -f /system/bin/app_process.orig ]
then
cp /system/bin/app_process /tmp/backup/
fi
}
# Restore Xposed Framework (bin/app_process)
xposed_restore()
{
if [ -f /tmp/backup/app_process ]
then
mv /system/bin/app_process /system/bin/app_process.orig
cp /tmp/backup/app_process /system/bin/
fi
}
# Preserve /system/addon.d in /tmp/addon.d
preserve_addon_d() {
mkdir -p /tmp/addon.d/
cp -a /system/addon.d/* /tmp/addon.d/
chmod 755 /tmp/addon.d/*.sh
}
# Restore /system/addon.d in /tmp/addon.d
restore_addon_d() {
cp -a /tmp/addon.d/* /system/addon.d/
rm -rf /tmp/addon.d/
}
[COLOR="Red"]# Proceed only if /system is the expected major and minor version
check_prereq() {
if ( ! grep -q "^ro.cm.version=$V.*" /system/build.prop ); then
echo "Not backing up files from incompatible version: $V"
return 0
fi
return 1
}[/COLOR]
check_blacklist() {
if [ -f /system/addon.d/blacklist ];then
## Discard any known bad backup scripts
cd /$1/addon.d/
for f in *sh; do
s=$(md5sum $f | awk {'print $1'})
grep -q $s /system/addon.d/blacklist && rm -f $f
done
fi
}
check_whitelist() {
found=0
if [ -f /system/addon.d/whitelist ];then
## forcefully keep any version-independent stuff
cd /$1/addon.d/
for f in *sh; do
s=$(md5sum $f | awk {'print $1'})
grep -q $s /system/addon.d/whitelist
if [ $? -eq 0 ]; then
found=1
else
rm -f $f
fi
done
fi
return $found
}
mkdir -p $saveroot
# Execute /system/addon.d/*.sh scripts with $1 parameter
run_stage() {
for script in $(find /tmp/addon.d/ -name '*.sh' |sort -n); do
$script $1
done
}
case "$1" in
backup)
save_props
mkdir -p $C
[COLOR="Red"]# if check_prereq; then[/COLOR]
if check_whitelist system; then
exit 127
fi
[COLOR="Red"]# fi[/COLOR]
check_blacklist system
xposed_backup
preserve_addon_d
run_stage pre-backup
run_stage backup
run_stage post-backup
;;
restore)
restore_props
[COLOR="Red"]# if check_prereq; then[/COLOR]
if check_whitelist tmp; then
exit 127
fi
[COLOR="Red"]# fi[/COLOR]
check_blacklist tmp
xposed_restore
run_stage pre-restore
run_stage restore
run_stage post-restore
restore_addon_d
rm -rf $C
rm -rf /data/data/android.pacstats
sync
;;
*)
echo "Usage: $0 {backup|restore}"
exit 1
esac
exit 0
backuptool.functions
Code:
#!/sbin/sh
#
# Functions for backuptool.sh
#
export C=/tmp/backup
export S=/system
export V=what you want
backup_file() {
if [ -e "$1" ]; then
local F=`basename "$1"`
local D=`dirname "$1"`
# dont backup any apps that have odex files, they are useless
if ( echo "$F" | grep -q "\.apk$" ) && [ -e `echo "$1" | sed -e 's/\.apk$/\.odex/'` ]; then
echo "Skipping odexed apk $1";
else
mkdir -p "$C/$D"
cp -p $1 "$C/$D/$F"
fi
fi
}
restore_file() {
local FILE=`basename "$1"`
local DIR=`dirname "$1"`
if [ -e "$C/$DIR/$FILE" ]; then
if [ ! -d "$DIR" ]; then
mkdir -p "$DIR";
fi
cp -p "$C/$DIR/$FILE" "$1";
if [ -n "$2" ]; then
echo "Deleting obsolete file $2"
rm "$2";
fi
fi
}
the files in attachments. just remove ".txt' at end to use them as well.
thanks.

LineageOS source compilation fails

I'm trying to build Lineage 14.1 for serranoltexx (for 5 days now).
When I started the compilation using "breakfast serranoltexx" an error appears after the 7 percent mark (~2minutes).
I followed this guide: wiki.lineageos. org/devices/serranoltexx/build
with a fresh Ubuntu 17.04 VM Box installation two times but that error always appears.
The only thing I still could mention is that pulled the proprietary blobs using my phone as stated in the instructions not with the stock Rom but Lineage 14.1 already installed.
Full console output:
(error at line #321) pastebin. com/vC06fV36
Error:
Code:
make: Leaving directory '/home/mrglue/android/lineage/kernel/samsung/msm8930-common'
[ 7% 2535/34256] Building Kernel
FAILED: /bin/bash -c "(make -j4 CFLAGS_MODULE=\"-fno-pic\" -C kernel/samsung/msm8930-common O=/home/mrglue/android/lineage/out/target/product/serranoltexx/obj/KERNEL_OBJ ARCH=arm CROSS_COMPILE=\"/home/mrglue/android/lineage/prebuilts/misc/linux-x86/ccache/ccache arm-linux-androidkernel-\" zImage ) && (if grep -q 'CONFIG_OF=y' /home/mrglue/android/lineage/out/target/product/serranoltexx/obj/KERNEL_OBJ/.config ; then echo \"Building DTBs\" ; make -j4 CFLAGS_MODULE=\"-fno-pic\" -C kernel/samsung/msm8930-common O=/home/mrglue/android/lineage/out/target/product/serranoltexx/obj/KERNEL_OBJ ARCH=arm CROSS_COMPILE=\"/home/mrglue/android/lineage/prebuilts/misc/linux-x86/ccache/ccache arm-linux-androidkernel-\" dtbs ; else echo \"DTBs not enabled\" ; fi ) && (if grep -q 'CONFIG_MODULES=y' /home/mrglue/android/lineage/out/target/product/serranoltexx/obj/KERNEL_OBJ/.config ; then echo \"Building Kernel Modules\" ; make -j4 CFLAGS_MODULE=\"-fno-pic\" -C kernel/samsung/msm8930-common O=/home/mrglue/android/lineage/out/target/product/serranoltexx/obj/KERNEL_OBJ ARCH=arm CROSS_COMPILE=\"/home/mrglue/android/lineage/prebuilts/misc/linux-x86/ccache/ccache arm-linux-androidkernel-\" modules && make -j4 CFLAGS_MODULE=\"-fno-pic\" -C kernel/samsung/msm8930-common O=/home/mrglue/android/lineage/out/target/product/serranoltexx/obj/KERNEL_OBJ INSTALL_MOD_PATH=../../system ARCH=arm CROSS_COMPILE=\"/home/mrglue/android/lineage/prebuilts/misc/linux-x86/ccache/ccache arm-linux-androidkernel-\" modules_install && mdpath=\`find /home/mrglue/android/lineage/out/target/product/serranoltexx/system/lib/modules -type f -name modules.order\`; if [ \"\$mdpath\" != \"\" ];then mpath=\`dirname \$mdpath\`; ko=\`find \$mpath/kernel -type f -name *.ko\`; for i in \$ko; do arm-linux-androidkernel-strip --strip-unneeded \$i; mv \$i /home/mrglue/android/lineage/out/target/product/serranoltexx/system/lib/modules/; done; fi && mdpath=\`find /home/mrglue/android/lineage/out/target/product/serranoltexx/system/lib/modules -type f -name modules.order\`; if [ \"\$mdpath\" != \"\" ];then mpath=\`dirname \$mdpath\`; rm -rf \$mpath; fi ; else echo \"Kernel Modules not enabled\" ; fi )"

Categories

Resources