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
3f83919e
Commit
3f83919e
authored
Jun 10, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bootloops when flashing Magisk after data wipe on FBE devices
parent
72a5b835
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
68 additions
and
41 deletions
+68
-41
bootstages.c
native/jni/core/bootstages.c
+55
-33
daemon.c
native/jni/core/daemon.c
+2
-1
daemon.h
native/jni/include/daemon.h
+1
-1
magiskrc.h
native/jni/include/magiskrc.h
+3
-2
flash_script.sh
scripts/flash_script.sh
+7
-4
No files found.
native/jni/core/bootstages.c
View file @
3f83919e
...
@@ -471,46 +471,31 @@ static const char wrapper[] =
...
@@ -471,46 +471,31 @@ static const char wrapper[] =
void
startup
()
{
void
startup
()
{
if
(
!
check_data
())
if
(
!
check_data
())
return
;
unblock_boot_process
();
if
(
access
(
SECURE_DIR
,
F_OK
)
!=
0
)
{
/* If the folder is not automatically created by the system,
* do NOT proceed further. Manual creation of the folder
* will cause bootloops on FBE devices. */
LOGE
(
SECURE_DIR
" is not present, abort..."
);
unblock_boot_process
();
}
// uninstaller or core-only mode
// No uninstaller or core-only mode
if
(
access
(
UNINSTALLER
,
F_OK
)
==
0
||
access
(
DISABLEFILE
,
F_OK
)
==
0
)
if
(
access
(
UNINSTALLER
,
F_OK
)
!=
0
&&
access
(
DISABLEFILE
,
F_OK
)
!=
0
)
{
goto
initialize
;
// Allocate buffer
buf
=
xmalloc
(
PATH_MAX
);
buf2
=
xmalloc
(
PATH_MAX
);
// Allocate buffer
simple_mount
(
"/system"
);
buf
=
xmalloc
(
PATH_MAX
);
simple_mount
(
"/vendor"
);
buf2
=
xmalloc
(
PATH_MAX
);
}
simple_mount
(
"/system"
);
simple_mount
(
"/vendor"
);
initialize:
LOGI
(
"** Initializing Magisk
\n
"
);
LOGI
(
"** Initializing Magisk
\n
"
);
// Unlock all blocks for rw
// Unlock all blocks for rw
unlock_blocks
();
unlock_blocks
();
// Magisk binaries
char
*
bin_path
=
NULL
;
if
(
access
(
"/cache/data_bin"
,
F_OK
)
==
0
)
bin_path
=
"/cache/data_bin"
;
else
if
(
access
(
"/data/data/com.topjohnwu.magisk/install"
,
F_OK
)
==
0
)
bin_path
=
"/data/data/com.topjohnwu.magisk/install"
;
else
if
(
access
(
"/data/user_de/0/com.topjohnwu.magisk/install"
,
F_OK
)
==
0
)
bin_path
=
"/data/user_de/0/com.topjohnwu.magisk/install"
;
if
(
bin_path
)
{
rm_rf
(
DATABIN
);
cp_afc
(
bin_path
,
DATABIN
);
rm_rf
(
bin_path
);
}
// Migration
rm_rf
(
"/data/magisk"
);
unlink
(
"/data/magisk.img"
);
unlink
(
"/data/magisk_debug.log"
);
xmkdir
(
"/data/adb"
,
0700
);
chmod
(
"/data/adb"
,
0700
);
LOGI
(
"* Creating /sbin overlay"
);
LOGI
(
"* Creating /sbin overlay"
);
DIR
*
dir
;
DIR
*
dir
;
struct
dirent
*
entry
;
struct
dirent
*
entry
;
...
@@ -579,6 +564,27 @@ initialize:
...
@@ -579,6 +564,27 @@ initialize:
close
(
sbin
);
close
(
sbin
);
close
(
root
);
close
(
root
);
// Alternative binaries paths
char
*
alt_bin
[]
=
{
"/cache/data_bin"
,
"/data/magisk"
,
"/data/data/com.topjohnwu.magisk/install"
,
"/data/user_de/0/com.topjohnwu.magisk/install"
,
NULL
};
char
*
bin_path
=
NULL
;
for
(
int
i
=
0
;
alt_bin
[
i
];
++
i
)
{
if
(
access
(
alt_bin
[
i
],
F_OK
)
==
0
)
{
bin_path
=
alt_bin
[
i
];
break
;
}
}
if
(
bin_path
)
{
rm_rf
(
DATABIN
);
cp_afc
(
bin_path
,
DATABIN
);
rm_rf
(
bin_path
);
}
// Remove legacy stuffs
unlink
(
"/data/magisk.img"
);
unlink
(
"/data/magisk_debug.log"
);
// Create directories in tmpfs overlay
// Create directories in tmpfs overlay
xmkdirs
(
MIRRDIR
"/system"
,
0755
);
xmkdirs
(
MIRRDIR
"/system"
,
0755
);
xmkdir
(
MIRRDIR
"/bin"
,
0755
);
xmkdir
(
MIRRDIR
"/bin"
,
0755
);
...
@@ -650,6 +656,9 @@ void post_fs_data(int client) {
...
@@ -650,6 +656,9 @@ void post_fs_data(int client) {
write_int
(
client
,
0
);
write_int
(
client
,
0
);
close
(
client
);
close
(
client
);
// If post-fs-data mode is started, it means startup succeeded
setup_done
=
1
;
// Start the debug log
// Start the debug log
start_debug_full_log
();
start_debug_full_log
();
...
@@ -669,6 +678,7 @@ void post_fs_data(int client) {
...
@@ -669,6 +678,7 @@ void post_fs_data(int client) {
goto
core_only
;
// Mounting fails, we can only do core only stuffs
goto
core_only
;
// Mounting fails, we can only do core only stuffs
restorecon
();
restorecon
();
chmod
(
SECURE_DIR
,
0700
);
// Run common scripts
// Run common scripts
LOGI
(
"* Running post-fs-data.d scripts
\n
"
);
LOGI
(
"* Running post-fs-data.d scripts
\n
"
);
...
@@ -765,12 +775,24 @@ void late_start(int client) {
...
@@ -765,12 +775,24 @@ void late_start(int client) {
write_int
(
client
,
0
);
write_int
(
client
,
0
);
close
(
client
);
close
(
client
);
if
(
access
(
SECURE_DIR
,
F_OK
)
!=
0
)
{
// It's safe to create the folder at this point if the system didn't create it
xmkdir
(
SECURE_DIR
,
0700
);
}
if
(
!
setup_done
)
{
// The setup failed for some reason, reboot and try again
exec_command_sync
(
"/system/bin/reboot"
,
NULL
);
return
;
}
// Allocate buffer
// Allocate buffer
if
(
buf
==
NULL
)
buf
=
xmalloc
(
PATH_MAX
);
if
(
buf
==
NULL
)
buf
=
xmalloc
(
PATH_MAX
);
if
(
buf2
==
NULL
)
buf2
=
xmalloc
(
PATH_MAX
);
if
(
buf2
==
NULL
)
buf2
=
xmalloc
(
PATH_MAX
);
// Wait till the full patch is done
// Wait till the full patch is done
waitpid
(
full_patch_pid
,
NULL
,
0
);
if
(
full_patch_pid
>
0
)
waitpid
(
full_patch_pid
,
NULL
,
0
);
// Run scripts after full patch, most reliable way to run scripts
// Run scripts after full patch, most reliable way to run scripts
LOGI
(
"* Running service.d scripts
\n
"
);
LOGI
(
"* Running service.d scripts
\n
"
);
...
...
native/jni/core/daemon.c
View file @
3f83919e
...
@@ -21,8 +21,9 @@
...
@@ -21,8 +21,9 @@
#include "resetprop.h"
#include "resetprop.h"
#include "magiskpolicy.h"
#include "magiskpolicy.h"
int
setup_done
=
0
;
int
seperate_vendor
=
0
;
int
seperate_vendor
=
0
;
int
full_patch_pid
;
int
full_patch_pid
=
-
1
;
static
void
*
request_handler
(
void
*
args
)
{
static
void
*
request_handler
(
void
*
args
)
{
int
client
=
*
((
int
*
)
args
);
int
client
=
*
((
int
*
)
args
);
...
...
native/jni/include/daemon.h
View file @
3f83919e
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
#include <sys/un.h>
#include <sys/un.h>
#include <sys/socket.h>
#include <sys/socket.h>
extern
int
is_daemon_init
;
extern
int
setup_done
;
extern
int
seperate_vendor
;
extern
int
seperate_vendor
;
extern
int
full_patch_pid
;
extern
int
full_patch_pid
;
...
...
native/jni/include/magiskrc.h
View file @
3f83919e
#include "magisk.h"
#include "magiskpolicy.h"
#include "magiskpolicy.h"
const
char
magiskrc
[]
=
const
char
magiskrc
[]
=
...
@@ -10,9 +11,9 @@ const char magiskrc[] =
...
@@ -10,9 +11,9 @@ const char magiskrc[] =
"on post-fs-data
\n
"
"on post-fs-data
\n
"
" load_persist_props
\n
"
" load_persist_props
\n
"
" rm
/dev/.magisk.unblock
\n
"
" rm
"
UNBLOCKFILE
"
\n
"
" start magisk_startup
\n
"
" start magisk_startup
\n
"
" wait
/dev/.magisk.unblock
10
\n
"
" wait
"
UNBLOCKFILE
"
10
\n
"
" rm /dev/.magisk.unblock
\n
"
" rm /dev/.magisk.unblock
\n
"
"
\n
"
"
\n
"
...
...
scripts/flash_script.sh
View file @
3f83919e
...
@@ -81,15 +81,18 @@ remove_system_su
...
@@ -81,15 +81,18 @@ remove_system_su
ui_print
"- Constructing environment"
ui_print
"- Constructing environment"
# Check if we can actually access the data (DE storage)
DATA
=
false
DATA
=
false
DATA_DE
=
false
if
grep
' /data '
/proc/mounts |
grep
-vq
'tmpfs'
;
then
if
grep
' /data '
/proc/mounts |
grep
-vq
'tmpfs'
;
then
[
!
-d
/data/adb
]
&&
mkdir
/data/adb
# Test if data is writable
touch
/data/adb/.write_test
&&
rm
/data/adb/.write_test
&&
DATA
=
true
touch
/data/.rw
&&
rm
/data/.rw
&&
DATA
=
true
# Test if DE storage is writable
$DATA
&&
[
-d
/data/adb
]
&&
touch
/data/adb/.rw
&&
rm
/data/adb/.rw
&&
DATA_DE
=
true
fi
fi
if
$DATA
;
then
if
$DATA
;
then
MAGISKBIN
=
/data/adb/magisk
MAGISKBIN
=
/data/magisk
$DATA_DE
&&
MAGISKBIN
=
/data/adb/magisk
run_migrations
run_migrations
else
else
MAGISKBIN
=
/cache/data_bin
MAGISKBIN
=
/cache/data_bin
...
...
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