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
76061296
Commit
76061296
authored
Jan 14, 2021
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Let MagiskBoot handle dtb fstab patching
parent
bb303d2d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
66 deletions
+36
-66
twostage.cpp
native/jni/init/twostage.cpp
+35
-65
dtb.cpp
native/jni/magiskboot/dtb.cpp
+1
-1
No files found.
native/jni/init/twostage.cpp
View file @
76061296
...
@@ -38,85 +38,55 @@ void FirstStageInit::prepare() {
...
@@ -38,85 +38,55 @@ void FirstStageInit::prepare() {
rename
(
"/.backup/init"
,
"/init"
);
rename
(
"/.backup/init"
,
"/init"
);
}
}
// Try to load fstab from dt
vector
<
fstab_entry
>
fstab
;
read_dt_fstab
(
fstab
);
char
fstab_file
[
128
];
char
fstab_file
[
128
];
fstab_file
[
0
]
=
'\0'
;
fstab_file
[
0
]
=
'\0'
;
// Find existing fstab file
// Find existing fstab file
for
(
const
char
*
hw
:
{
cmd
->
fstab_suffix
,
cmd
->
hardware
,
cmd
->
hardware_plat
})
{
for
(
const
char
*
suffix
:
{
cmd
->
fstab_suffix
,
cmd
->
hardware
,
cmd
->
hardware_plat
})
{
if
(
hw
[
0
]
==
'\0'
)
if
(
suffix
[
0
]
==
'\0'
)
continue
;
sprintf
(
fstab_file
,
"fstab.%s"
,
hw
);
if
(
access
(
fstab_file
,
F_OK
)
!=
0
)
{
fstab_file
[
0
]
=
'\0'
;
continue
;
continue
;
}
else
{
for
(
const
char
*
prefix
:
{
"odm/etc/fstab"
,
"vendor/etc/fstab"
,
"fstab"
})
{
LOGD
(
"Found fstab file: %s
\n
"
,
fstab_file
);
sprintf
(
fstab_file
,
"%s.%s"
,
prefix
,
suffix
);
break
;
if
(
access
(
fstab_file
,
F_OK
)
!=
0
)
{
fstab_file
[
0
]
=
'\0'
;
}
else
{
LOGD
(
"Found fstab file: %s
\n
"
,
fstab_file
);
goto
exit_loop
;
}
}
}
}
}
exit_loop
:
if
(
fstab
.
empty
())
{
if
(
fstab_file
[
0
]
==
'\0'
)
{
// fstab has to be somewhere in ramdisk
LOGI
(
"Cannot find fstab file in ramdisk!
\n
"
);
if
(
fstab_file
[
0
]
==
'\0'
)
{
return
;
LOGE
(
"Cannot find fstab file in ramdisk!
\n
"
);
}
return
;
}
// Parse and load fstab file
file_readline
(
fstab_file
,
[
&
](
string_view
l
)
->
bool
{
if
(
l
[
0
]
==
'#'
||
l
.
length
()
==
1
)
return
true
;
char
*
line
=
(
char
*
)
l
.
data
();
int
dev0
,
dev1
,
mnt_point0
,
mnt_point1
,
type0
,
type1
,
mnt_flags0
,
mnt_flags1
,
fsmgr_flags0
,
fsmgr_flags1
;
sscanf
(
line
,
"%n%*s%n %n%*s%n %n%*s%n %n%*s%n %n%*s%n"
,
// Parse and load fstab file
&
dev0
,
&
dev1
,
&
mnt_point0
,
&
mnt_point1
,
&
type0
,
&
type1
,
vector
<
fstab_entry
>
fstab
;
&
mnt_flags0
,
&
mnt_flags1
,
&
fsmgr_flags0
,
&
fsmgr_flags1
);
file_readline
(
fstab_file
,
[
&
](
string_view
l
)
->
bool
{
if
(
l
[
0
]
==
'#'
||
l
.
length
()
==
1
)
return
true
;
char
*
line
=
(
char
*
)
l
.
data
();
fstab_entry
entry
;
int
dev0
,
dev1
,
mnt_point0
,
mnt_point1
,
type0
,
type1
,
mnt_flags0
,
mnt_flags1
,
fsmgr_flags0
,
fsmgr_flags1
;
set_info
(
dev
);
sscanf
(
line
,
"%n%*s%n %n%*s%n %n%*s%n %n%*s%n %n%*s%n"
,
set_info
(
mnt_point
);
&
dev0
,
&
dev1
,
&
mnt_point0
,
&
mnt_point1
,
&
type0
,
&
type1
,
set_info
(
type
);
&
mnt_flags0
,
&
mnt_flags1
,
&
fsmgr_flags0
,
&
fsmgr_flags1
);
set_info
(
mnt_flags
);
set_info
(
fsmgr_flags
);
fstab
.
emplace_back
(
std
::
move
(
entry
));
fstab_entry
entry
;
return
true
;
});
}
else
{
// All dt fstab entries should be first_stage_mount
for
(
auto
&
entry
:
fstab
)
{
if
(
!
str_contains
(
entry
.
fsmgr_flags
,
"first_stage_mount"
))
{
if
(
!
entry
.
fsmgr_flags
.
empty
())
entry
.
fsmgr_flags
+=
','
;
entry
.
fsmgr_flags
+=
"first_stage_mount"
;
}
}
// Dump dt fstab to fstab file in rootfs
set_info
(
dev
);
if
(
fstab_file
[
0
]
==
'\0'
)
{
set_info
(
mnt_point
);
const
char
*
suffix
=
set_info
(
type
);
cmd
->
fstab_suffix
[
0
]
?
cmd
->
fstab_suffix
:
set_info
(
mnt_flags
);
(
cmd
->
hardware
[
0
]
?
cmd
->
hardware
:
set_info
(
fsmgr_flags
);
(
cmd
->
hardware_plat
[
0
]
?
cmd
->
hardware_plat
:
nullptr
));
if
(
suffix
==
nullptr
)
{
LOGE
(
"Cannot determine fstab suffix!
\n
"
);
return
;
}
sprintf
(
fstab_file
,
"fstab.%s"
,
suffix
);
}
// Patch init to force IsDtFstabCompatible() return false
fstab
.
emplace_back
(
std
::
move
(
entry
));
auto
init
=
mmap_data
::
rw
(
"/init"
);
return
true
;
init
.
patch
({
make_pair
(
"android,fstab"
,
"xxx"
)
});
});
}
{
{
LOGD
(
"Write fstab file: %s
\n
"
,
fstab_file
);
LOGD
(
"Write fstab file: %s
\n
"
,
fstab_file
);
...
...
native/jni/magiskboot/dtb.cpp
View file @
76061296
...
@@ -207,7 +207,7 @@ static bool fdt_patch(void *fdt) {
...
@@ -207,7 +207,7 @@ static bool fdt_patch(void *fdt) {
int
node
;
int
node
;
fdt_for_each_subnode
(
node
,
fdt
,
fstab
)
{
fdt_for_each_subnode
(
node
,
fdt
,
fstab
)
{
const
char
*
name
=
fdt_get_name
(
fdt
,
node
,
nullptr
);
const
char
*
name
=
fdt_get_name
(
fdt
,
node
,
nullptr
);
//
Always patch verity if 2SI
//
Force remove AVB for 2SI since it may bootloop some devices
int
len
;
int
len
;
auto
value
=
(
const
char
*
)
fdt_getprop
(
fdt
,
node
,
"fsmgr_flags"
,
&
len
);
auto
value
=
(
const
char
*
)
fdt_getprop
(
fdt
,
node
,
"fsmgr_flags"
,
&
len
);
string
copy
(
value
,
len
);
string
copy
(
value
,
len
);
...
...
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