AddingADBRootToAnImage » History » Version 14
Denis 'GNUtoo' Carikli, 05/17/2020 09:04 PM
initramfs repacking: Add spacing
1 | 8 | Denis 'GNUtoo' Carikli | h1. AddingADBRootToAnImage |
---|---|---|---|
2 | 1 | Denis 'GNUtoo' Carikli | |
3 | 12 | Denis 'GNUtoo' Carikli | h2. Adding adb root support to an existing Replicant release. |
4 | |||
5 | 6 | Denis 'GNUtoo' Carikli | In this tutorial we'll add adb root support to an existing Replicant release. |
6 | |||
7 | This is valid for the following configuration: |
||
8 | * *Image*: replicant-6.0-0004-rc1-maguro.zip |
||
9 | * *Device*: Galaxy Nexus (GT-I9250) |
||
10 | |||
11 | 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. |
12 | |||
13 | 6 | Denis 'GNUtoo' Carikli | You'll need to adapt it slightly for other devices. |
14 | |||
15 | 3 | Denis 'GNUtoo' Carikli | First extract the boot.img from the zip |
16 | 1 | Denis 'GNUtoo' Carikli | <pre> |
17 | $ mkdir temp |
||
18 | $ cd temp |
||
19 | $ unzip ../replicant-6.0-0004-rc1-maguro.zip |
||
20 | $ file boot.img |
||
21 | boot.img: Android bootimg, kernel, ramdisk, page size: 2048, cmdline (androidboot.hardware=tuna) |
||
22 | </pre> |
||
23 | |||
24 | 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: |
25 | 1 | Denis 'GNUtoo' Carikli | <pre> |
26 | $ unbootimg --kernel kernel.img --ramdisk ramdisk.cpio.gz -i boot.img | tee boot.txt |
||
27 | total image size: 5619712 |
||
28 | kernel size: 4604340 |
||
29 | kernel load addr: 0x80008000 |
||
30 | ramdisk size: 1009915 |
||
31 | ramdisk load addr: 0x81000000 |
||
32 | 2nd boot size: 0 |
||
33 | 2nd boot load addr: 0x80f00000 |
||
34 | kernel tags addr: 0x80000100 |
||
35 | page size: 2048 |
||
36 | board: `' |
||
37 | cmdline: `androidboot.hardware=tuna' |
||
38 | id: 9b90141066f527ecd3909d2ab8e383ebd995fd40000 |
||
39 | </pre> |
||
40 | |||
41 | 3 | Denis 'GNUtoo' Carikli | Then uncompress the initramfs |
42 | 1 | Denis 'GNUtoo' Carikli | <pre> |
43 | $ gunzip ramdisk.cpio.gz |
||
44 | $ file ramdisk.cpio |
||
45 | ramdisk.cpio: ASCII cpio archive (SVR4 with no CRC) |
||
46 | </pre> |
||
47 | |||
48 | 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): |
49 | 1 | Denis 'GNUtoo' Carikli | <pre> |
50 | 4 | Denis 'GNUtoo' Carikli | $ sed 's#ro.adb.secure=1# #' -i ramdisk.cpio |
51 | 3 | Denis 'GNUtoo' Carikli | $ sed 's#ro.secure=1#ro.secure=0#' -i ramdisk.cpio |
52 | 1 | Denis 'GNUtoo' Carikli | $ sed 's#persist.sys.usb.config=none#persist.sys.usb.config=adb #' -i ramdisk.cpio |
53 | 2 | Denis 'GNUtoo' Carikli | </pre> |
54 | 1 | Denis 'GNUtoo' Carikli | |
55 | 3 | Denis 'GNUtoo' Carikli | Then recompress the initramfs |
56 | 1 | Denis 'GNUtoo' Carikli | <pre> |
57 | $ gzip ramdisk.cpio |
||
58 | 3 | Denis 'GNUtoo' Carikli | </pre> |
59 | |||
60 | 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: |
||
61 | <pre> |
||
62 | 1 | Denis 'GNUtoo' Carikli | $ mkbootimg --cmdline="androidboot.hardware=tuna" --kernel kernel.img --ramdisk ramdisk.cpio.gz --base 0x80000000 -o boot_new.img |
63 | </pre> |
||
64 | |||
65 | 3 | Denis 'GNUtoo' Carikli | Verify that we got all the arguments right: |
66 | 1 | Denis 'GNUtoo' Carikli | <pre> |
67 | $ unbootimg -i boot_new.img | tee boot_new.txt |
||
68 | $ diff -u boot.txt boot_new.txt |
||
69 | $ --- boot.txt 2020-02-18 00:39:59.890285634 +0100 |
||
70 | +++ boot_new.txt 2020-02-18 00:44:16.208897037 +0100 |
||
71 | @@ -1,7 +1,7 @@ |
||
72 | total image size: 5619712 |
||
73 | kernel size: 4604340 |
||
74 | kernel load addr: 0x80008000 |
||
75 | -ramdisk size: 1009915 |
||
76 | +ramdisk size: 1010280 |
||
77 | ramdisk load addr: 0x81000000 |
||
78 | 2nd boot size: 0 |
||
79 | 2nd boot load addr: 0x80f00000 |
||
80 | @@ -9,4 +9,4 @@ |
||
81 | page size: 2048 |
||
82 | board: `' |
||
83 | cmdline: `androidboot.hardware=tuna' |
||
84 | -id: 9b90141066f527ecd3909d2ab8e383ebd995fd40000 |
||
85 | +id: dd37b2ae1e50be62fe5c94b81b85aa56ffea17be000 |
||
86 | 3 | Denis 'GNUtoo' Carikli | </pre> |
87 | |||
88 | 7 | Denis 'GNUtoo' Carikli | You can then reflash the boot.img image. |
89 | |||
90 | Don't forget to adjust the heimdall arguments for your device. |
||
91 | |||
92 | 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). |
||
93 | 3 | Denis 'GNUtoo' Carikli | <pre> |
94 | heimdall flash --boot boot.img --recovery boot.img |
||
95 | 1 | Denis 'GNUtoo' Carikli | </pre> |
96 | 5 | Denis 'GNUtoo' Carikli | |
97 | Then you can use adb: |
||
98 | <pre> |
||
99 | $ adb logcat -b main |
||
100 | </pre> |
||
101 | 10 | Denis 'GNUtoo' Carikli | |
102 | h2. Example for the GT-I9300 |
||
103 | |||
104 | This is valid for the following configuration: |
||
105 | * *Image*: replicant-6.0-0004-rc1-i9300.zip |
||
106 | * *Device*: Galaxy SIII (GT-I9300) |
||
107 | |||
108 | For other devices like the GT-I9300, the boot.img (or recovery.img) have other parameters: |
||
109 | <pre> |
||
110 | unbootimg -i boot.img |
||
111 | total image size: 4239360 |
||
112 | kernel size: 3391376 |
||
113 | kernel load addr: 0x40008000 |
||
114 | ramdisk size: 844653 |
||
115 | ramdisk load addr: 0x41000000 |
||
116 | 2nd boot size: 0 |
||
117 | 2nd boot load addr: 0x40f00000 |
||
118 | kernel tags addr: 0x40000100 |
||
119 | page size: 2048 |
||
120 | board: `' |
||
121 | cmdline: `console=ttySAC2,115200' |
||
122 | id: d34c0412b72d37a2287331e28d902a769c4a86e9000 |
||
123 | </pre> |
||
124 | 11 | Denis 'GNUtoo' Carikli | |
125 | So we need to adjust the --cmdline and the --base accordingly: |
||
126 | <pre> |
||
127 | mkbootimg --cmdline="console=ttySAC2,115200" --kernel kernel.img --ramdisk ramdisk.cpio.gz --base 0x40000000 -o boot_new.img |
||
128 | </pre> |
||
129 | |||
130 | Like with the Galaxy nexus, when we recreate the image with the infos we saved in boot.txt, we need to make sure that the base is right. |
||
131 | |||
132 | Here the base is 0x40000000, which results in the kernel offset (or load address) of 0x40008000. |
||
133 | 12 | Denis 'GNUtoo' Carikli | |
134 | 13 | Denis 'GNUtoo' Carikli | h2. Going further |
135 | 12 | Denis 'GNUtoo' Carikli | |
136 | 14 | Denis 'GNUtoo' Carikli | The Linux kernel has more in depth documentation about initramfs in a file named "ramfs-rootfs-initramfs.rst":https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/filesystems/ramfs-rootfs-initramfs.rst?h=v5.7-rc5 which document how to extract an initramfs and how to recreate one. |
137 | |||
138 | However we didn't test that yet. Tests and tutorials are welcome. |
||
139 | |||
140 | We also need to understand if something specific needs to be done for the file permissions when extracting, modifying and rebuilding an initramfs. |