Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
88db822c
Commit
88db822c
authored
Jun 20, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Get device blocks with sysfs
parent
fbf3588f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
34 deletions
+38
-34
util_functions.sh
scripts/util_functions.sh
+38
-34
No files found.
scripts/util_functions.sh
View file @
88db822c
...
@@ -45,21 +45,37 @@ ui_print() {
...
@@ -45,21 +45,37 @@ ui_print() {
$BOOTMODE
&&
echo
"
$1
"
||
echo
-e
"ui_print
$1
\n
ui_print"
>>
/proc/self/fd/
$OUTFD
$BOOTMODE
&&
echo
"
$1
"
||
echo
-e
"ui_print
$1
\n
ui_print"
>>
/proc/self/fd/
$OUTFD
}
}
toupper
()
{
echo
"
$@
"
|
tr
'[:lower:]'
'[:upper:]'
}
find_block
()
{
for
uevent
in
/sys/dev/block/
*
/uevent
;
do
local
DEVNAME
=
`
grep_prop DEVNAME
$uevent
`
local
PARTNAME
=
`
grep_prop PARTNAME
$uevent
`
for
p
in
"
$@
"
;
do
if
[
"
`
toupper
$p
`
"
=
"
`
toupper
$PARTNAME
`
"
]
;
then
echo
/dev/block/
$DEVNAME
return
0
fi
done
done
return
1
}
mount_partitions
()
{
mount_partitions
()
{
# Check A/B slot
# Check A/B slot
if
[
"
`
grep_prop ro.build.ab_update
`
"
=
"true"
]
;
then
SLOT
=
`
grep_cmdline androidboot.slot_suffix
`
SLOT
=
`
grep_cmdline androidboot.slot_suffix
`
if
[
-z
$SLOT
]
;
then
if
[
-z
$SLOT
]
;
then
SLOT
=
_
`
grep_cmdline androidboot.slot
`
SLOT
=
_
`
grep_cmdline androidboot.slot
`
[
$SLOT
=
"_"
]
&&
SLOT
=
[
$SLOT
=
"_"
]
&&
SLOT
=
fi
fi
fi
[
-z
$SLOT
]
||
ui_print
"-
A/B partition, curren
t slot:
$SLOT
"
[
-z
$SLOT
]
||
ui_print
"-
Current boo
t slot:
$SLOT
"
ui_print
"- Mounting /system, /vendor"
ui_print
"- Mounting /system, /vendor"
[
-f
/system/build.prop
]
||
is_mounted /system
||
mount
-o
ro /system 2>/dev/null
[
-f
/system/build.prop
]
||
is_mounted /system
||
mount
-o
ro /system 2>/dev/null
if
!
is_mounted /system
&&
!
[
-f
/system/build.prop
]
;
then
if
!
is_mounted /system
&&
!
[
-f
/system/build.prop
]
;
then
SYSTEMBLOCK
=
`
find
/dev/block
-iname
system
$SLOT
|
head
-n
1
`
SYSTEMBLOCK
=
`
find
_block system
$SLOT
`
mount
-t
ext4
-o
ro
$SYSTEMBLOCK
/system
mount
-t
ext4
-o
ro
$SYSTEMBLOCK
/system
fi
fi
[
-f
/system/build.prop
]
||
is_mounted /system
||
abort
"! Cannot mount /system"
[
-f
/system/build.prop
]
||
is_mounted /system
||
abort
"! Cannot mount /system"
...
@@ -75,7 +91,7 @@ mount_partitions() {
...
@@ -75,7 +91,7 @@ mount_partitions() {
# Seperate /vendor partition
# Seperate /vendor partition
is_mounted /vendor
||
mount
-o
ro /vendor 2>/dev/null
is_mounted /vendor
||
mount
-o
ro /vendor 2>/dev/null
if
!
is_mounted /vendor
;
then
if
!
is_mounted /vendor
;
then
VENDORBLOCK
=
`
find
/dev/block
-iname
vendor
$SLOT
|
head
-n
1
`
VENDORBLOCK
=
`
find
_block vendor
$SLOT
`
mount
-t
ext4
-o
ro
$VENDORBLOCK
/vendor
mount
-t
ext4
-o
ro
$VENDORBLOCK
/vendor
fi
fi
is_mounted /vendor
||
abort
"! Cannot mount /vendor"
is_mounted /vendor
||
abort
"! Cannot mount /vendor"
...
@@ -109,14 +125,14 @@ get_flags() {
...
@@ -109,14 +125,14 @@ get_flags() {
}
}
grep_cmdline
()
{
grep_cmdline
()
{
REGEX
=
"s/^
$1
=//p"
local
REGEX
=
"s/^
$1
=//p"
sed
-E
's/ +/\n/g'
/proc/cmdline |
sed
-n
"
$REGEX
"
2>/dev/null
sed
-E
's/ +/\n/g'
/proc/cmdline |
sed
-n
"
$REGEX
"
2>/dev/null
}
}
grep_prop
()
{
grep_prop
()
{
REGEX
=
"s/^
$1
=//p"
local
REGEX
=
"s/^
$1
=//p"
shift
shift
FILES
=
$@
local
FILES
=
$@
[
-z
"
$FILES
"
]
&&
FILES
=
'/system/build.prop'
[
-z
"
$FILES
"
]
&&
FILES
=
'/system/build.prop'
sed
-n
"
$REGEX
"
$FILES
2>/dev/null |
head
-n
1
sed
-n
"
$REGEX
"
$FILES
2>/dev/null |
head
-n
1
}
}
...
@@ -128,26 +144,6 @@ getvar() {
...
@@ -128,26 +144,6 @@ getvar() {
[
!
-z
$VALUE
]
&&
eval
$VARNAME
=
\$
VALUE
[
!
-z
$VALUE
]
&&
eval
$VARNAME
=
\$
VALUE
}
}
find_boot_image
()
{
BOOTIMAGE
=
if
[
!
-z
$SLOT
]
;
then
BOOTIMAGE
=
`
find /dev/block
-iname
boot
$SLOT
|
head
-n
1
`
2>/dev/null
else
for
BLOCK
in
ramdisk boot_a kern-a android_boot kernel boot lnx bootimg
;
do
BOOTIMAGE
=
`
find /dev/block
-iname
$BLOCK
|
head
-n
1
`
2>/dev/null
[
!
-z
$BOOTIMAGE
]
&&
break
done
fi
# Recovery fallback
if
[
-z
$BOOTIMAGE
]
;
then
for
FSTAB
in
/etc/
*
fstab
*
;
do
BOOTIMAGE
=
`
grep
-v
'#'
$FSTAB
|
grep
-E
'/boot[^a-zA-Z]'
|
grep
-oE
'/dev/[a-zA-Z0-9_./-]*'
`
[
!
-z
$BOOTIMAGE
]
&&
break
done
fi
[
!
-z
$BOOTIMAGE
]
&&
BOOTIMAGE
=
`
readlink
-f
$BOOTIMAGE
`
}
run_migrations
()
{
run_migrations
()
{
# Update the broken boot backup
# Update the broken boot backup
if
[
-f
/data/stock_boot_.img.gz
]
;
then
if
[
-f
/data/stock_boot_.img.gz
]
;
then
...
@@ -175,6 +171,15 @@ run_migrations() {
...
@@ -175,6 +171,15 @@ run_migrations() {
[
-L
/data/magisk.img
]
||
mv
/data/magisk.img /data/adb/magisk.img 2>/dev/null
[
-L
/data/magisk.img
]
||
mv
/data/magisk.img /data/adb/magisk.img 2>/dev/null
}
}
find_boot_image
()
{
BOOTIMAGE
=
if
[
!
-z
$SLOT
]
;
then
BOOTIMAGE
=
`
find_block boot
$SLOT
ramdisk
$SLOT
`
else
BOOTIMAGE
=
`
find_block boot_a kern-a android_boot kernel boot lnx bootimg
`
fi
}
flash_boot_image
()
{
flash_boot_image
()
{
# Make sure all blocks are writable
# Make sure all blocks are writable
$MAGISKBIN
/magisk
--unlock-blocks
2>/dev/null
$MAGISKBIN
/magisk
--unlock-blocks
2>/dev/null
...
@@ -201,8 +206,7 @@ flash_boot_image() {
...
@@ -201,8 +206,7 @@ flash_boot_image() {
}
}
find_dtbo_image
()
{
find_dtbo_image
()
{
DTBOIMAGE
=
`
find /dev/block
-iname
dtbo
$SLOT
|
head
-n
1
`
2>/dev/null
DTBOIMAGE
=
`
find_block dtbo
$SLOT
`
[
!
-z
$DTBOIMAGE
]
&&
DTBOIMAGE
=
`
readlink
-f
$DTBOIMAGE
`
}
}
patch_dtbo_image
()
{
patch_dtbo_image
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment