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
b7e2e972
Commit
b7e2e972
authored
Mar 13, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support boot_img_hdr_v2
parent
650b2ce6
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
61 additions
and
36 deletions
+61
-36
bootimg.cpp
native/jni/magiskboot/bootimg.cpp
+23
-8
bootimg.h
native/jni/magiskboot/bootimg.h
+28
-21
magiskboot.h
native/jni/magiskboot/magiskboot.h
+2
-1
main.cpp
native/jni/magiskboot/main.cpp
+7
-6
boot_patch.sh
scripts/boot_patch.sh
+1
-0
No files found.
native/jni/magiskboot/bootimg.cpp
View file @
b7e2e972
...
...
@@ -149,6 +149,10 @@ int boot_img::parse_image(uint8_t *head) {
pos
+=
hdr
.
recovery_dtbo_size
();
pos_align
();
dtb
=
head
+
pos
;
pos
+=
hdr
.
dtb_size
();
pos_align
();
if
(
head
+
pos
<
map_addr
+
map_size
)
{
tail
=
head
+
pos
;
tail_size
=
map_size
-
(
tail
-
map_addr
);
...
...
@@ -227,10 +231,10 @@ void boot_img::find_dtb() {
continue
;
}
dtb
=
kernel
+
i
;
dt_size
=
hdr
->
kernel_size
-
i
;
kernel_
dtb
=
kernel
+
i
;
kernel_
dt_size
=
hdr
->
kernel_size
-
i
;
hdr
->
kernel_size
=
i
;
fprintf
(
stderr
,
"
DTB [%u]
\n
"
,
dt_size
);
fprintf
(
stderr
,
"
KERNEL_DTB [%u]
\n
"
,
kernel_
dt_size
);
break
;
}
}
...
...
@@ -242,6 +246,7 @@ void boot_img::print_hdr() {
fprintf
(
stderr
,
"SECOND_SZ [%u]
\n
"
,
hdr
->
second_size
);
fprintf
(
stderr
,
"EXTRA_SZ [%u]
\n
"
,
hdr
.
extra_size
());
fprintf
(
stderr
,
"RECOV_DTBO_SZ [%u]
\n
"
,
hdr
.
recovery_dtbo_size
());
fprintf
(
stderr
,
"DTB [%u]
\n
"
,
hdr
.
dtb_size
());
uint32_t
ver
=
hdr
.
os_version
();
if
(
ver
)
{
...
...
@@ -308,7 +313,7 @@ int unpack(const char *image, bool hdr) {
}
// Dump dtb
dump
(
boot
.
dtb
,
boot
.
dt_size
,
DTB_FILE
);
dump
(
boot
.
kernel_dtb
,
boot
.
kernel_dt_size
,
KER_
DTB_FILE
);
// Dump ramdisk
if
(
COMPRESSED
(
boot
.
r_fmt
))
{
...
...
@@ -327,6 +332,9 @@ int unpack(const char *image, bool hdr) {
// Dump recovery_dtbo
dump
(
boot
.
recov_dtbo
,
boot
.
hdr
.
recovery_dtbo_size
(),
RECV_DTBO_FILE
);
// Dump dtb
dump
(
boot
.
dtb
,
boot
.
hdr
.
dtb_size
(),
DTB_FILE
);
return
ret
;
}
...
...
@@ -343,7 +351,8 @@ void repack(const char* orig_image, const char* out_image) {
boot
.
hdr
->
kernel_size
=
0
;
boot
.
hdr
->
ramdisk_size
=
0
;
boot
.
hdr
->
second_size
=
0
;
boot
.
dt_size
=
0
;
boot
.
hdr
.
dtb_size
()
=
0
;
boot
.
kernel_dt_size
=
0
;
fprintf
(
stderr
,
"Repack to boot image: [%s]
\n
"
,
out_image
);
...
...
@@ -417,9 +426,9 @@ void repack(const char* orig_image, const char* out_image) {
munmap
(
raw_buf
,
raw_size
);
}
// dtb
if
(
access
(
DTB_FILE
,
R_OK
)
==
0
)
boot
.
hdr
->
kernel_size
+=
restore
(
DTB_FILE
,
fd
);
//
kernel
dtb
if
(
access
(
KER_
DTB_FILE
,
R_OK
)
==
0
)
boot
.
hdr
->
kernel_size
+=
restore
(
KER_
DTB_FILE
,
fd
);
file_align
();
// ramdisk
...
...
@@ -462,6 +471,12 @@ void repack(const char* orig_image, const char* out_image) {
file_align
();
}
// dtb
if
(
access
(
DTB_FILE
,
R_OK
)
==
0
)
{
boot
.
hdr
.
dtb_size
()
=
restore
(
DTB_FILE
,
fd
);
file_align
();
}
// Append tail info
if
(
boot
.
flags
&
SEANDROID_FLAG
)
{
restore_buf
(
fd
,
SEANDROID_MAGIC
"
\xFF\xFF\xFF\xFF
"
,
20
);
...
...
native/jni/magiskboot/bootimg.h
View file @
b7e2e972
#pragma once
#include <stdint.h>
#include "format.h"
#ifndef _BOOT_IMAGE_H_
#define _BOOT_IMAGE_H_
struct
boot_img_hdr_base
{
char
magic
[
8
];
...
...
@@ -46,13 +45,18 @@ struct boot_img_hdr_v0 : public boot_img_hdr_base {
}
__attribute__
((
packed
));
struct
boot_img_hdr_v1
:
public
boot_img_hdr_v0
{
uint32_t
recovery_dtbo_size
;
/* size in bytes for recovery DTB
O image */
uint64_t
recovery_dtbo_offset
;
/* offset to recovery dtb
o in boot image */
uint32_t
recovery_dtbo_size
;
/* size in bytes for recovery DTBO/ACPI
O image */
uint64_t
recovery_dtbo_offset
;
/* offset to recovery dtbo/acpi
o in boot image */
uint32_t
header_size
;
}
__attribute__
((
packed
));
struct
boot_img_hdr_v2
:
public
boot_img_hdr_v1
{
uint32_t
dtb_size
;
/* size in bytes for DTB image */
uint64_t
dtb_addr
;
/* physical load address for DTB image */
}
__attribute__
((
packed
));
// Default to hdr v1
typedef
boot_img_hdr_v
1
boot_img_hdr
;
typedef
boot_img_hdr_v
2
boot_img_hdr
;
// Special Samsung header
struct
boot_img_hdr_pxa
:
public
boot_img_hdr_base
{
...
...
@@ -84,12 +88,15 @@ struct boot_img_hdr_pxa : public boot_img_hdr_base {
** +-----------------+
** | recovery dtbo | q pages
** +-----------------+
** | dtb | r pages
** +-----------------+
**
** n = (kernel_size + page_size - 1) / page_size
** m = (ramdisk_size + page_size - 1) / page_size
** o = (second_size + page_size - 1) / page_size
** p = (extra_size + page_size - 1) / page_size
** q = (recovery_dtbo_size + page_size - 1) / page_size
** r = (dtb_size + page_size - 1) / page_size
**
** 0. all entities are page_size aligned in flash
** 1. kernel and ramdisk are required (size != 0)
...
...
@@ -145,14 +152,14 @@ struct blob_hdr {
struct
dyn_img_hdr
{
#define dyn_access(x) (pxa ? hdr_pxa->x : v
1
_hdr->x)
#define dyn_access(x) (pxa ? hdr_pxa->x : v
2
_hdr->x)
#define dyn_get(name, type) \
type name() const { return dyn_access(name); }
#define dyn_ref(name, type) \
type &name() { return dyn_access(name); }
#define v
1
_ref(name, type, alt) \
type &name() { if (pxa) { alt = 0; return alt; } return v
1
_hdr->name; }
#define v
2
_ref(name, type, alt) \
type &name() { if (pxa) { alt = 0; return alt; } return v
2
_hdr->name; }
dyn_ref
(
page_size
,
uint32_t
);
dyn_get
(
name
,
char
*
);
...
...
@@ -160,23 +167,24 @@ type &name() { if (pxa) { alt = 0; return alt; } return v1_hdr->name; }
dyn_get
(
id
,
char
*
);
dyn_get
(
extra_cmdline
,
char
*
);
v1_ref
(
os_version
,
uint32_t
,
j32
);
v1_ref
(
recovery_dtbo_size
,
uint32_t
,
j32
);
v1_ref
(
recovery_dtbo_offset
,
uint64_t
,
j64
);
v1_ref
(
header_size
,
uint32_t
,
j32
);
v2_ref
(
os_version
,
uint32_t
,
j32
);
v2_ref
(
recovery_dtbo_size
,
uint32_t
,
j32
);
v2_ref
(
recovery_dtbo_offset
,
uint64_t
,
j64
);
v2_ref
(
header_size
,
uint32_t
,
j32
);
v2_ref
(
dtb_size
,
uint32_t
,
j32
);
dyn_img_hdr
()
:
pxa
(
false
),
img_hdr
(
nullptr
)
{}
~
dyn_img_hdr
()
{
if
(
pxa
)
delete
hdr_pxa
;
else
delete
v
1
_hdr
;
delete
v
2
_hdr
;
}
uint32_t
header_version
()
{
// There won't be v4 header any time soon...
// If larger than 4, assume this field will be treated as extra_size
return
pxa
||
v
1_hdr
->
header_version
>
4
?
0
:
v1
_hdr
->
header_version
;
return
pxa
||
v
2_hdr
->
header_version
>
4
?
0
:
v2
_hdr
->
header_version
;
}
uint32_t
&
extra_size
()
{
...
...
@@ -193,7 +201,7 @@ type &name() { if (pxa) { alt = 0; return alt; } return v1_hdr->name; }
}
void
set_hdr
(
boot_img_hdr
*
h
)
{
v
1
_hdr
=
h
;
v
2
_hdr
=
h
;
}
void
set_hdr
(
boot_img_hdr_pxa
*
h
)
{
...
...
@@ -216,7 +224,7 @@ private:
* but both of them is a base header.
* Same address can be interpreted in 3 ways */
boot_img_hdr_base
*
img_hdr
;
/* Common base header */
boot_img_hdr
*
v
1_hdr
;
/* AOSP v1
header */
boot_img_hdr
*
v
2_hdr
;
/* AOSP v2
header */
boot_img_hdr_pxa
*
hdr_pxa
;
/* Samsung PXA header */
};
...
...
@@ -243,8 +251,8 @@ struct boot_img {
format_t
r_fmt
;
// Pointer to dtb that is appended after kernel
uint8_t
*
dtb
;
uint32_t
dt_size
;
uint8_t
*
kernel_
dtb
;
uint32_t
kernel_
dt_size
;
// Pointer to end of image
uint8_t
*
tail
;
...
...
@@ -256,6 +264,7 @@ struct boot_img {
uint8_t
*
second
;
uint8_t
*
extra
;
uint8_t
*
recov_dtbo
;
uint8_t
*
dtb
;
~
boot_img
();
...
...
@@ -264,5 +273,3 @@ struct boot_img {
void
find_dtb
();
void
print_hdr
();
};
#endif
native/jni/magiskboot/magiskboot.h
View file @
b7e2e972
...
...
@@ -7,8 +7,9 @@
#define RAMDISK_FILE "ramdisk.cpio"
#define SECOND_FILE "second"
#define EXTRA_FILE "extra"
#define
DTB_FILE "
dtb"
#define
KER_DTB_FILE "kernel_
dtb"
#define RECV_DTBO_FILE "recovery_dtbo"
#define DTB_FILE "dtb"
#define NEW_BOOT "new-boot.img"
// Main entries
...
...
native/jni/magiskboot/main.cpp
View file @
b7e2e972
...
...
@@ -122,9 +122,10 @@ int main(int argc, char *argv[]) {
unlink
(
KERNEL_FILE
);
unlink
(
RAMDISK_FILE
);
unlink
(
SECOND_FILE
);
unlink
(
DTB_FILE
);
unlink
(
KER_
DTB_FILE
);
unlink
(
EXTRA_FILE
);
unlink
(
RECV_DTBO_FILE
);
unlink
(
DTB_FILE
);
}
else
if
(
argc
>
2
&&
strcmp
(
argv
[
1
],
"sha1"
)
==
0
)
{
uint8_t
sha1
[
SHA_DIGEST_SIZE
];
void
*
buf
;
...
...
@@ -147,16 +148,16 @@ int main(int argc, char *argv[]) {
repack
(
argv
[
2
],
argv
[
3
]
?
argv
[
3
]
:
NEW_BOOT
);
}
else
if
(
argc
>
2
&&
strcmp
(
argv
[
1
],
"decompress"
)
==
0
)
{
decompress
(
argv
[
2
],
argv
[
3
]);
}
else
if
(
argc
>
2
&&
strncmp
(
argv
[
1
],
"compress"
,
10
)
==
0
)
{
compress
(
argv
[
1
][
10
]
==
'='
?
&
argv
[
1
][
11
]
:
"gzip"
,
argv
[
2
],
argv
[
3
]);
}
else
if
(
argc
>
2
&&
strncmp
(
argv
[
1
],
"compress"
,
8
)
==
0
)
{
compress
(
argv
[
1
][
8
]
==
'='
?
&
argv
[
1
][
9
]
:
"gzip"
,
argv
[
2
],
argv
[
3
]);
}
else
if
(
argc
>
4
&&
strcmp
(
argv
[
1
],
"hexpatch"
)
==
0
)
{
hexpatch
(
argv
[
2
],
argv
[
3
],
argv
[
4
]);
}
else
if
(
argc
>
2
&&
strcmp
(
argv
[
1
],
"cpio"
)
==
0
)
{
if
(
cpio_commands
(
argc
-
2
,
argv
+
2
))
usage
(
argv
[
0
]);
}
else
if
(
argc
>
2
&&
strncmp
(
argv
[
1
],
"dtb"
,
5
)
==
0
)
{
if
(
argv
[
1
][
5
]
!=
'-'
)
}
else
if
(
argc
>
2
&&
strncmp
(
argv
[
1
],
"dtb"
,
3
)
==
0
)
{
if
(
argv
[
1
][
3
]
!=
'-'
)
usage
(
argv
[
0
]);
if
(
dtb_commands
(
&
argv
[
1
][
6
],
argc
-
2
,
argv
+
2
))
if
(
dtb_commands
(
&
argv
[
1
][
4
],
argc
-
2
,
argv
+
2
))
usage
(
argv
[
0
]);
}
else
{
usage
(
argv
[
0
]);
...
...
scripts/boot_patch.sh
View file @
b7e2e972
...
...
@@ -154,6 +154,7 @@ rm -f ramdisk.cpio.orig config
if
!
$KEEPVERITY
;
then
[
-f
dtb
]
&&
./magiskboot dtb-patch dtb
&&
ui_print
"- Removing dm(avb)-verity in dtb"
[
-f
kernel_dtb
]
&&
./magiskboot dtb-patch kernel_dtb
&&
ui_print
"- Removing dm(avb)-verity in dtb"
[
-f
extra
]
&&
./magiskboot dtb-patch extra
&&
ui_print
"- Removing dm(avb)-verity in extra-dtb"
fi
...
...
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