Project

General

Profile

AddingADBRootToAnImage » History » Version 9

Denis 'GNUtoo' Carikli, 02/22/2020 10:58 PM
mention where to get unbootimg

1 8 Denis 'GNUtoo' Carikli
h1. AddingADBRootToAnImage
2 1 Denis 'GNUtoo' Carikli
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 9 Denis 'GNUtoo' Carikli
You also need to have unbootimg installed. In Parabola this is part of the "fso-unbootimg package":https://www.parabola.nu/packages/?sort=&q=fso-unbootimg . It's also possible to compile that tool by hand or to other alternative tools that do exactly the same thing.
10
11 6 Denis 'GNUtoo' Carikli
You'll need to adapt it slightly for other devices.
12
13 3 Denis 'GNUtoo' Carikli
First extract the boot.img from the zip
14 1 Denis 'GNUtoo' Carikli
<pre>
15
$ mkdir temp
16
$ cd temp 
17
$ unzip ../replicant-6.0-0004-rc1-maguro.zip
18
$ file boot.img
19
boot.img: Android bootimg, kernel, ramdisk, page size: 2048, cmdline (androidboot.hardware=tuna)
20
</pre>
21
22 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:
23 1 Denis 'GNUtoo' Carikli
<pre>
24
$ unbootimg --kernel kernel.img --ramdisk ramdisk.cpio.gz -i boot.img | tee boot.txt
25
total image size:   5619712
26
kernel size:        4604340
27
kernel load addr:   0x80008000
28
ramdisk size:       1009915
29
ramdisk load addr:  0x81000000
30
2nd boot size:      0
31
2nd boot load addr: 0x80f00000
32
kernel tags addr:   0x80000100
33
page size:          2048
34
board:              `'
35
cmdline:            `androidboot.hardware=tuna'
36
id:                 9b90141066f527ecd3909d2ab8e383ebd995fd40000
37
</pre>
38
39 3 Denis 'GNUtoo' Carikli
Then uncompress the initramfs
40 1 Denis 'GNUtoo' Carikli
<pre>
41
$ gunzip ramdisk.cpio.gz
42
$ file ramdisk.cpio 
43
ramdisk.cpio: ASCII cpio archive (SVR4 with no CRC)
44
</pre>
45
46 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):
47 1 Denis 'GNUtoo' Carikli
<pre>
48 4 Denis 'GNUtoo' Carikli
$ sed 's#ro.adb.secure=1#               #' -i ramdisk.cpio
49 3 Denis 'GNUtoo' Carikli
$ sed 's#ro.secure=1#ro.secure=0#' -i ramdisk.cpio
50 1 Denis 'GNUtoo' Carikli
$ sed 's#persist.sys.usb.config=none#persist.sys.usb.config=adb #' -i ramdisk.cpio
51 2 Denis 'GNUtoo' Carikli
</pre>
52 1 Denis 'GNUtoo' Carikli
53 3 Denis 'GNUtoo' Carikli
Then recompress the initramfs
54 1 Denis 'GNUtoo' Carikli
<pre>
55
$ gzip ramdisk.cpio
56 3 Denis 'GNUtoo' Carikli
</pre>
57
58
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:
59
<pre>
60 1 Denis 'GNUtoo' Carikli
$ mkbootimg --cmdline="androidboot.hardware=tuna" --kernel kernel.img --ramdisk ramdisk.cpio.gz  --base 0x80000000 -o boot_new.img
61
</pre>
62
63 3 Denis 'GNUtoo' Carikli
Verify that we got all the arguments right:
64 1 Denis 'GNUtoo' Carikli
<pre>
65
$ unbootimg -i boot_new.img | tee boot_new.txt
66
$ diff -u boot.txt boot_new.txt
67
$ --- boot.txt	2020-02-18 00:39:59.890285634 +0100
68
+++ boot_new.txt	2020-02-18 00:44:16.208897037 +0100
69
@@ -1,7 +1,7 @@
70
 total image size:   5619712
71
 kernel size:        4604340
72
 kernel load addr:   0x80008000
73
-ramdisk size:       1009915
74
+ramdisk size:       1010280
75
 ramdisk load addr:  0x81000000
76
 2nd boot size:      0
77
 2nd boot load addr: 0x80f00000
78
@@ -9,4 +9,4 @@
79
 page size:          2048
80
 board:              `'
81
 cmdline:            `androidboot.hardware=tuna'
82
-id:                 9b90141066f527ecd3909d2ab8e383ebd995fd40000
83
+id:                 dd37b2ae1e50be62fe5c94b81b85aa56ffea17be000
84 3 Denis 'GNUtoo' Carikli
</pre>
85
86 7 Denis 'GNUtoo' Carikli
You can then reflash the boot.img image.
87
88
Don't forget to adjust the heimdall arguments for your device.
89
90
If in doubt, it's better to consult the Replicant installation instructions that have the good heimdall arguments, as wrong arguments can completely break your device, making it too complicated to repair (you'd have to un-solder and re-solder resistors that are hardly visible).
91 3 Denis 'GNUtoo' Carikli
<pre>
92
heimdall flash --boot boot.img --recovery boot.img
93 1 Denis 'GNUtoo' Carikli
</pre>
94 5 Denis 'GNUtoo' Carikli
95
Then you can use adb:
96
<pre>
97
$ adb logcat -b main
98
</pre>