Project

General

Profile

AddingADBRootToAnImage » History » Version 6

Denis 'GNUtoo' Carikli, 02/17/2020 11:56 PM

1 1 Denis 'GNUtoo' Carikli
h1. AddingADB
2
3 6 Denis 'GNUtoo' Carikli
In this tutorial we'll add adb root support to an existing Replicant release.
4
5
This is valid for the following configuration:
6
* *Image*: replicant-6.0-0004-rc1-maguro.zip
7
* *Device*: Galaxy Nexus (GT-I9250)
8
9
You'll need to adapt it slightly for other devices.
10
11 3 Denis 'GNUtoo' Carikli
First extract the boot.img from the zip
12 1 Denis 'GNUtoo' Carikli
<pre>
13
$ mkdir temp
14
$ cd temp 
15
$ unzip ../replicant-6.0-0004-rc1-maguro.zip
16
$ file boot.img
17
boot.img: Android bootimg, kernel, ramdisk, page size: 2048, cmdline (androidboot.hardware=tuna)
18
</pre>
19
20 3 Denis 'GNUtoo' Carikli
Then extract the kernel, and initramfs from the boot.img. Also save the infos such as the load address, etc in boot.txt:
21 1 Denis 'GNUtoo' Carikli
<pre>
22
$ unbootimg --kernel kernel.img --ramdisk ramdisk.cpio.gz -i boot.img | tee boot.txt
23
total image size:   5619712
24
kernel size:        4604340
25
kernel load addr:   0x80008000
26
ramdisk size:       1009915
27
ramdisk load addr:  0x81000000
28
2nd boot size:      0
29
2nd boot load addr: 0x80f00000
30
kernel tags addr:   0x80000100
31
page size:          2048
32
board:              `'
33
cmdline:            `androidboot.hardware=tuna'
34
id:                 9b90141066f527ecd3909d2ab8e383ebd995fd40000
35
</pre>
36
37 3 Denis 'GNUtoo' Carikli
Then uncompress the initramfs
38 1 Denis 'GNUtoo' Carikli
<pre>
39
$ gunzip ramdisk.cpio.gz
40
$ file ramdisk.cpio 
41
ramdisk.cpio: ASCII cpio archive (SVR4 with no CRC)
42
</pre>
43
44 3 Denis 'GNUtoo' Carikli
Then edit the default.props, we use sed on the raw cpio image for simplicity (we don't have permissions and username to take care of this way):
45 1 Denis 'GNUtoo' Carikli
<pre>
46 4 Denis 'GNUtoo' Carikli
$ sed 's#ro.adb.secure=1#               #' -i ramdisk.cpio
47 3 Denis 'GNUtoo' Carikli
$ sed 's#ro.secure=1#ro.secure=0#' -i ramdisk.cpio
48 1 Denis 'GNUtoo' Carikli
$ sed 's#persist.sys.usb.config=none#persist.sys.usb.config=adb #' -i ramdisk.cpio
49 2 Denis 'GNUtoo' Carikli
</pre>
50 1 Denis 'GNUtoo' Carikli
51 3 Denis 'GNUtoo' Carikli
Then recompress the initramfs
52 1 Denis 'GNUtoo' Carikli
<pre>
53
$ gzip ramdisk.cpio
54 3 Denis 'GNUtoo' Carikli
</pre>
55
56
We then recreate the image with the infos we saved in boot.txt. Note that the base is 0x80000000. The kernel has an offset and will be in 0x80008000:
57
<pre>
58 1 Denis 'GNUtoo' Carikli
$ mkbootimg --cmdline="androidboot.hardware=tuna" --kernel kernel.img --ramdisk ramdisk.cpio.gz  --base 0x80000000 -o boot_new.img
59
</pre>
60
61 3 Denis 'GNUtoo' Carikli
Verify that we got all the arguments right:
62 1 Denis 'GNUtoo' Carikli
<pre>
63
$ unbootimg -i boot_new.img | tee boot_new.txt
64
$ diff -u boot.txt boot_new.txt
65
$ --- boot.txt	2020-02-18 00:39:59.890285634 +0100
66
+++ boot_new.txt	2020-02-18 00:44:16.208897037 +0100
67
@@ -1,7 +1,7 @@
68
 total image size:   5619712
69
 kernel size:        4604340
70
 kernel load addr:   0x80008000
71
-ramdisk size:       1009915
72
+ramdisk size:       1010280
73
 ramdisk load addr:  0x81000000
74
 2nd boot size:      0
75
 2nd boot load addr: 0x80f00000
76
@@ -9,4 +9,4 @@
77
 page size:          2048
78
 board:              `'
79
 cmdline:            `androidboot.hardware=tuna'
80
-id:                 9b90141066f527ecd3909d2ab8e383ebd995fd40000
81
+id:                 dd37b2ae1e50be62fe5c94b81b85aa56ffea17be000
82 3 Denis 'GNUtoo' Carikli
</pre>
83
84
Reflash the image:
85
<pre>
86
heimdall flash --boot boot.img --recovery boot.img
87 1 Denis 'GNUtoo' Carikli
</pre>
88 5 Denis 'GNUtoo' Carikli
89
Then you can use adb:
90
<pre>
91
$ adb logcat -b main
92
</pre>