Commit 1e877808 authored by topjohnwu's avatar topjohnwu

Fix link errors for flash scripts

parent 1777d9f7
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
# #
########################################################################################## ##########################################################################################
# Workaround for getting the full path of BOOTIMAGE
CWD=`pwd` CWD=`pwd`
cd `dirname $1` cd `dirname $1`
BOOTIMAGE="`pwd`/`basename $1`" BOOTIMAGE="`pwd`/`basename $1`"
...@@ -41,6 +42,10 @@ fi ...@@ -41,6 +42,10 @@ fi
# Detect whether running as root # Detect whether running as root
[ `id -u` -eq 0 ] && ROOT=true || ROOT=false [ `id -u` -eq 0 ] && ROOT=true || ROOT=false
# Prefer binaries and libs in /system
ENV='LD_LIBRARY_PATH=/system/lib:/vendor/lib:/sbin PATH=/system/bin:/system/xbin:/sbin'
[ -d /system/lib64 ] && ENV='LD_LIBRARY_PATH=/system/lib64:/vendor/lib64:/sbin PATH=/system/bin:/system/xbin:/sbin'
# Call ui_print_wrap if exists, or else simply use echo # Call ui_print_wrap if exists, or else simply use echo
# Useful when wrapped in flashable zip # Useful when wrapped in flashable zip
ui_print_wrap() { ui_print_wrap() {
...@@ -59,17 +64,17 @@ grep_prop() { ...@@ -59,17 +64,17 @@ grep_prop() {
# --cpio-add <incpio> <mode> <entry> <infile> # --cpio-add <incpio> <mode> <entry> <infile>
cpio_add() { cpio_add() {
./magiskboot --cpio-add ramdisk.cpio $1 $2 $3 eval $ENV ./magiskboot --cpio-add ramdisk.cpio $1 $2 $3
} }
# --cpio-extract <incpio> <entry> <outfile> # --cpio-extract <incpio> <entry> <outfile>
cpio_extract() { cpio_extract() {
./magiskboot --cpio-extract ramdisk.cpio $1 $2 eval $ENV ./magiskboot --cpio-extract ramdisk.cpio $1 $2
} }
# --cpio-mkdir <incpio> <mode> <entry> # --cpio-mkdir <incpio> <mode> <entry>
cpio_mkdir() { cpio_mkdir() {
./magiskboot --cpio-mkdir ramdisk.cpio $1 $2 eval $ENV ./magiskboot --cpio-mkdir ramdisk.cpio $1 $2
} }
########################################################################################## ##########################################################################################
...@@ -81,7 +86,7 @@ cpio_mkdir() { ...@@ -81,7 +86,7 @@ cpio_mkdir() {
chmod +x ./* chmod +x ./*
ui_print_wrap "- Unpacking boot image" ui_print_wrap "- Unpacking boot image"
./magiskboot --unpack "$BOOTIMAGE" eval $ENV ./magiskboot --unpack "$BOOTIMAGE"
case $? in case $? in
1 ) 1 )
...@@ -105,28 +110,28 @@ esac ...@@ -105,28 +110,28 @@ esac
# Test patch status and do restore, after this section, ramdisk.cpio.orig is guaranteed to exist # Test patch status and do restore, after this section, ramdisk.cpio.orig is guaranteed to exist
ui_print_wrap "- Checking ramdisk status" ui_print_wrap "- Checking ramdisk status"
./magiskboot --cpio-test ramdisk.cpio eval $ENV ./magiskboot --cpio-test ramdisk.cpio
case $? in case $? in
0 ) # Stock boot 0 ) # Stock boot
ui_print_wrap "- Stock boot image detected!" ui_print_wrap "- Stock boot image detected!"
ui_print_wrap "- Backing up stock boot image" ui_print_wrap "- Backing up stock boot image"
SHA1=`./magiskboot --sha1 "$BOOTIMAGE" | tail -n 1` SHA1=`eval $ENV ./magiskboot --sha1 "$BOOTIMAGE" | tail -n 1`
STOCKDUMP=stock_boot_${SHA1}.img STOCKDUMP=stock_boot_${SHA1}.img
dd if="$BOOTIMAGE" of=$STOCKDUMP dd if="$BOOTIMAGE" of=$STOCKDUMP
./magiskboot --compress $STOCKDUMP eval $ENV ./magiskboot --compress $STOCKDUMP
cp -af ramdisk.cpio ramdisk.cpio.orig cp -af ramdisk.cpio ramdisk.cpio.orig
;; ;;
1 ) # Magisk patched 1 ) # Magisk patched
ui_print_wrap "- Magisk patched image detected!" ui_print_wrap "- Magisk patched image detected!"
# Find SHA1 of stock boot image # Find SHA1 of stock boot image
if [ -z $SHA1 ]; then if [ -z $SHA1 ]; then
./magiskboot --cpio-extract ramdisk.cpio init.magisk.rc init.magisk.rc.old eval $ENV ./magiskboot --cpio-extract ramdisk.cpio init.magisk.rc init.magisk.rc.old
SHA1=`grep_prop "# STOCKSHA1" init.magisk.rc.old` SHA1=`grep_prop "# STOCKSHA1" init.magisk.rc.old`
rm -f init.magisk.rc.old rm -f init.magisk.rc.old
fi fi
OK=false OK=false
./magiskboot --cpio-restore ramdisk.cpio eval $ENV ./magiskboot --cpio-restore ramdisk.cpio
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
ui_print_wrap "- Ramdisk restored from internal backup" ui_print_wrap "- Ramdisk restored from internal backup"
OK=true OK=true
...@@ -138,8 +143,8 @@ case $? in ...@@ -138,8 +143,8 @@ case $? in
STOCKDUMP=/data/stock_boot_${SHA1}.img STOCKDUMP=/data/stock_boot_${SHA1}.img
if [ -f ${STOCKDUMP}.gz ]; then if [ -f ${STOCKDUMP}.gz ]; then
ui_print_wrap "- Stock boot image backup found" ui_print_wrap "- Stock boot image backup found"
./magiskboot --decompress ${STOCKDUMP}.gz stock_boot.img eval $ENV ./magiskboot --decompress ${STOCKDUMP}.gz stock_boot.img
./magiskboot --unpack stock_boot.img eval $ENV ./magiskboot --unpack stock_boot.img
rm -f stock_boot.img rm -f stock_boot.img
OK=true OK=true
fi fi
...@@ -165,8 +170,8 @@ esac ...@@ -165,8 +170,8 @@ esac
ui_print_wrap "- Patching ramdisk" ui_print_wrap "- Patching ramdisk"
# The common patches # The common patches
$KEEPVERITY || ./magiskboot --cpio-patch-dmverity ramdisk.cpio $KEEPVERITY || eval $ENV ./magiskboot --cpio-patch-dmverity ramdisk.cpio
$KEEPFORCEENCRYPT || ./magiskboot --cpio-patch-forceencrypt ramdisk.cpio $KEEPFORCEENCRYPT || eval $ENV ./magiskboot --cpio-patch-forceencrypt ramdisk.cpio
# Add magisk entrypoint # Add magisk entrypoint
cpio_extract init.rc init.rc cpio_extract init.rc init.rc
...@@ -177,7 +182,7 @@ rm -f init.rc ...@@ -177,7 +182,7 @@ rm -f init.rc
# sepolicy patches # sepolicy patches
cpio_extract sepolicy sepolicy cpio_extract sepolicy sepolicy
./magisk magiskpolicy --load sepolicy --save sepolicy --minimal eval $ENV ./magisk magiskpolicy --load sepolicy --save sepolicy --minimal
cpio_add 644 sepolicy sepolicy cpio_add 644 sepolicy sepolicy
rm -f sepolicy rm -f sepolicy
...@@ -187,11 +192,11 @@ if [ ! -z $SHA1 ]; then ...@@ -187,11 +192,11 @@ if [ ! -z $SHA1 ]; then
echo "# STOCKSHA1=$SHA1" >> init.magisk.rc echo "# STOCKSHA1=$SHA1" >> init.magisk.rc
fi fi
cpio_add 750 init.magisk.rc init.magisk.rc cpio_add 750 init.magisk.rc init.magisk.rc
[ -f init.magisk.rc.bak ] && mv init.magisk.rc.bak init.magisk.rc mv init.magisk.rc.bak init.magisk.rc 2>/dev/null
cpio_add 755 sbin/magisk magisk cpio_add 755 sbin/magisk magisk
# Create ramdisk backups # Create ramdisk backups
./magiskboot --cpio-backup ramdisk.cpio ramdisk.cpio.orig eval $ENV ./magiskboot --cpio-backup ramdisk.cpio ramdisk.cpio.orig
rm -f ramdisk.cpio.orig rm -f ramdisk.cpio.orig
...@@ -202,16 +207,16 @@ rm -f ramdisk.cpio.orig ...@@ -202,16 +207,16 @@ rm -f ramdisk.cpio.orig
# Hexpatches # Hexpatches
# Remove Samsung RKP in stock kernel # Remove Samsung RKP in stock kernel
./magiskboot --hexpatch kernel \ eval $ENV ./magiskboot --hexpatch kernel \
49010054011440B93FA00F71E9000054010840B93FA00F7189000054001840B91FA00F7188010054 \ 49010054011440B93FA00F71E9000054010840B93FA00F7189000054001840B91FA00F7188010054 \
A1020054011440B93FA00F7140020054010840B93FA00F71E0010054001840B91FA00F7181010054 A1020054011440B93FA00F7140020054010840B93FA00F71E0010054001840B91FA00F7181010054
ui_print_wrap "- Repacking boot image" ui_print_wrap "- Repacking boot image"
./magiskboot --repack "$BOOTIMAGE" eval $ENV ./magiskboot --repack "$BOOTIMAGE"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
ui_print_wrap "! Unable to repack boot image!" ui_print_wrap "! Unable to repack boot image!"
exit 1 exit 1
fi fi
./magiskboot --cleanup eval $ENV ./magiskboot --cleanup
...@@ -81,7 +81,7 @@ getvar() { ...@@ -81,7 +81,7 @@ getvar() {
find_boot_image() { find_boot_image() {
if [ -z "$BOOTIMAGE" ]; then if [ -z "$BOOTIMAGE" ]; then
for PARTITION in kern-a android_boot kernel boot lnx; do for PARTITION in kern-a android_boot kernel boot lnx; do
BOOTIMAGE=`find /dev -iname "$PARTITION"` BOOTIMAGE=`find /dev/block -iname "$PARTITION" | head -n 1`
[ ! -z $BOOTIMAGE ] && break [ ! -z $BOOTIMAGE ] && break
done done
fi fi
...@@ -198,9 +198,8 @@ fi ...@@ -198,9 +198,8 @@ fi
# Prefer binaries and libs in /system # Prefer binaries and libs in /system
[ -e /vendor ] || ln -s /system/vendor /vendor [ -e /vendor ] || ln -s /system/vendor /vendor
export PATH=/system/bin:/system/xbin:/vendor/bin:$PATH ENV='LD_LIBRARY_PATH=/system/lib:/vendor/lib:/sbin PATH=/system/bin:/system/xbin:/sbin'
export LD_LIBRARY_PATH=/system/lib:/vendor/lib:/sbin [ -d /system/lib64 ] && ENV='LD_LIBRARY_PATH=/system/lib64:/vendor/lib64:/sbin PATH=/system/bin:/system/xbin:/sbin'
[ -d /system/lib64 ] && export LD_LIBRARY_PATH=/system/lib64:/vendor/lib64:/sbin
# read override variables # read override variables
getvar KEEPVERITY getvar KEEPVERITY
...@@ -233,8 +232,6 @@ ui_print "- Device platform: $ARCH" ...@@ -233,8 +232,6 @@ ui_print "- Device platform: $ARCH"
BINDIR=$INSTALLER/$ARCH BINDIR=$INSTALLER/$ARCH
chmod -R 755 $CHROMEDIR $BINDIR chmod -R 755 $CHROMEDIR $BINDIR
$IS64BIT && SYSTEMLIB=/system/lib64 || SYSTEMLIB=/system/lib
find_boot_image find_boot_image
if [ -z $BOOTIMAGE ]; then if [ -z $BOOTIMAGE ]; then
ui_print "! Unable to detect boot image" ui_print "! Unable to detect boot image"
...@@ -262,7 +259,7 @@ chcon -hR u:object_r:system_file:s0 $MAGISKBIN ...@@ -262,7 +259,7 @@ chcon -hR u:object_r:system_file:s0 $MAGISKBIN
########################################################################################## ##########################################################################################
# Fix SuperSU..... # Fix SuperSU.....
$BOOTMODE && $BINDIR/magiskpolicy --live "allow fsck * * *" $BOOTMODE && eval $ENV $BINDIR/magiskpolicy --live "allow fsck * * *"
if (is_mounted /data); then if (is_mounted /data); then
IMG=/data/magisk.img IMG=/data/magisk.img
...@@ -275,7 +272,7 @@ if [ -f $IMG ]; then ...@@ -275,7 +272,7 @@ if [ -f $IMG ]; then
ui_print "- $IMG detected!" ui_print "- $IMG detected!"
else else
ui_print "- Creating $IMG" ui_print "- Creating $IMG"
$BINDIR/magisk --createimg $IMG 64M eval $ENV $BINDIR/magisk --createimg $IMG 64M
fi fi
mount_image $IMG /magisk mount_image $IMG /magisk
...@@ -306,7 +303,7 @@ if [ -f /data/stock_boot.img ]; then ...@@ -306,7 +303,7 @@ if [ -f /data/stock_boot.img ]; then
SHA1=`$BINDIR/magiskboot --sha1 /data/stock_boot.img | tail -n 1` SHA1=`$BINDIR/magiskboot --sha1 /data/stock_boot.img | tail -n 1`
STOCKDUMP=/data/stock_boot_${SHA1}.img STOCKDUMP=/data/stock_boot_${SHA1}.img
mv /data/stock_boot.img $STOCKDUMP mv /data/stock_boot.img $STOCKDUMP
$BINDIR/magiskboot --compress $STOCKDUMP eval $ENV $BINDIR/magiskboot --compress $STOCKDUMP
fi fi
SOURCEDMODE=true SOURCEDMODE=true
...@@ -319,7 +316,7 @@ cd $MAGISKBIN ...@@ -319,7 +316,7 @@ cd $MAGISKBIN
if [ -f chromeos ]; then if [ -f chromeos ]; then
echo > empty echo > empty
$CHROMEDIR/futility vbutil_kernel --pack new-boot.img.signed \ eval $ENV $CHROMEDIR/futility vbutil_kernel --pack new-boot.img.signed \
--keyblock $CHROMEDIR/kernel.keyblock --signprivate $CHROMEDIR/kernel_data_key.vbprivk \ --keyblock $CHROMEDIR/kernel.keyblock --signprivate $CHROMEDIR/kernel_data_key.vbprivk \
--version 1 --vmlinuz new-boot.img --config empty --arch arm --bootloader empty --flags 0x1 --version 1 --vmlinuz new-boot.img --config empty --arch arm --bootloader empty --flags 0x1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment