Project

General

Profile

GalaxyNexusI9250SerialConsole » History » Version 20

Denis 'GNUtoo' Carikli, 01/29/2020 11:20 PM

1 16 Paul Kocialkowski
h1. Galaxy Nexus (I9250) Serial Console
2 1 Denis 'GNUtoo' Carikli
3 19 Denis 'GNUtoo' Carikli
See [[SamsungSerial]] for the hardware setup.
4 1 Denis 'GNUtoo' Carikli
5 19 Denis 'GNUtoo' Carikli
h2. Without patching the kernel on Replicant 6
6
7
Adding @loglevel=8 fiq_debugger.console_enable=1 fiq_debugger.no_sleep=1@ to the kernel command line enables to see some of the boot of the kernel without having to recompile the kernel.
8
9
Though it requires to repack a boot.img to add the commandline arguments.
10
<pre>
11
IMAGE ?= boot.img
12
EXTRA_CMDLINE ?= loglevel=8 fiq_debugger.console_enable=1 fiq_debugger.no_sleep=1
13
14
.PHONY: $(IMAGE) flash
15
$(IMAGE):
16
	unbootimg --kernel kernel \
17
		--ramdisk ramdisk \
18
		-i ../$(IMAGE)
19
	mkbootimg \
20
		--kernel kernel \
21
		--ramdisk ramdisk \
22
		--base 0x80000000 \
23
		--cmdline "androidboot.hardware=tuna ${EXTRA_CMDLINE}" \
24
		-o $(IMAGE)
25
flash:
26
	fastboot flash boot $(IMAGE)
27
	fastboot flash recovery $(IMAGE)
28
	fastboot boot $(IMAGE)
29
</pre>
30
31 20 Denis 'GNUtoo' Carikli
h2. Real serial console by patching the kernel
32 1 Denis 'GNUtoo' Carikli
33
When you connect the cable you get the FIQ debugger, but what if you want kgdb instead:
34
* apply that patch:
35
<pre>
36
diff --git a/arch/arm/mach-omap2/board-tuna.c b/arch/arm/mach-omap2/board-tuna.c
37
index a022a43..7098227 100644
38
--- a/arch/arm/mach-omap2/board-tuna.c
39
+++ b/arch/arm/mach-omap2/board-tuna.c
40
@@ -1001,6 +1001,8 @@ static inline void __init board_serial_init(void)
41
        omap_serial_init_port_pads(0, uart1_pads, uart1_pads_sz, NULL);
42
        omap_serial_init_port_pads(1, tuna_uart2_pads,
43
                ARRAY_SIZE(tuna_uart2_pads), &tuna_uart2_info);
44
+       omap_serial_init_port_pads(2,tuna_uart3_pads,
45
+               ARRAY_SIZE(tuna_uart3_pads), NULL);
46
        omap_serial_init_port_pads(3, tuna_uart4_pads,
47
                                   ARRAY_SIZE(tuna_uart4_pads), NULL);
48
 }
49
</pre>
50
* remove the FIQ debugger in the kernel configuration.
51
52
* change the CMDLINE trough the kernel configuration:
53
Use:
54
<pre>CONFIG_CMDLINE="console=ttyO2 androidboot.console=ttyO2 [...]"</pre>
55
Instead of:
56
<pre>CONFIG_CMDLINE="console=ttyFIQ0 androidboot.console=ttyFIQ0 [...]"</pre>
57 2 Denis 'GNUtoo' Carikli
58 3 Denis 'GNUtoo' Carikli
* Verify that you get the kernel messages.
59 1 Denis 'GNUtoo' Carikli
60 2 Denis 'GNUtoo' Carikli
h2. KGDB
61 12 Denis 'GNUtoo' Carikli
62 20 Denis 'GNUtoo' Carikli
* You need to change the cmdline for kgdb
63 4 Denis 'GNUtoo' Carikli
<pre>
64
CONFIG_CMDLINE="kgdboc=ttyO2,115200 console=ttyO2 androidboot.console=ttyO2 [...]"
65
</pre>
66
67
Don't add kgdbwait tough because it result in that:
68
<pre>
69
(gdb) set remotebaud 115200
70
(gdb) target remote /dev/ttyUSB0
71
/dev/ttyUSB0: Device or resource busy.
72
(gdb) target remote /dev/ttyUSB0
73
Remote debugging using /dev/ttyUSB0
74
kgdb_breakpoint ()
75
    at /home/gnutoo/embedded/android/replicant-4.0/kernel/samsung/tuna/kernel/debug/debug_core.c:954
76
954		arch_kgdb_breakpoint();
77
(gdb) c
78
Continuing.
79
80
Program received signal SIGSEGV, Segmentation fault.
81
__raw_spin_lock_irqsave (lock=0x288)
82
    at /home/gnutoo/embedded/android/replicant-4.0/kernel/samsung/tuna/kernel/spinlock.c:112
83
112	BUILD_LOCK_OPS(spin, raw_spinlock);
84
(gdb) bt
85
#0  __raw_spin_lock_irqsave (lock=0x288)
86
    at /home/gnutoo/embedded/android/replicant-4.0/kernel/samsung/tuna/kernel/spinlock.c:112
87
#1  0xc061aecc in _raw_spin_lock_irqsave (lock=0x288)
88
    at /home/gnutoo/embedded/android/replicant-4.0/kernel/samsung/tuna/kernel/spinlock.c:145
89
#2  0xc0098620 in try_to_wake_up (p=0x0, state=1611595795, wake_flags=1)
90
    at /home/gnutoo/embedded/android/replicant-4.0/kernel/samsung/tuna/kernel/sched.c:2681
91
#3  0xc009897c in wake_up_process (p=0x288)
92
    at /home/gnutoo/embedded/android/replicant-4.0/kernel/samsung/tuna/kernel/sched.c:2785
93
#4  0xc00e2090 in proc_dohung_task_timeout_secs (table=<value optimized out>, write=<value optimized out>, 
94
    buffer=<value optimized out>, lenp=<value optimized out>, ppos=0xc782bf70)
95
    at /home/gnutoo/embedded/android/replicant-4.0/kernel/samsung/tuna/kernel/hung_task.c:190
96
#5  0xc0174178 in proc_sys_call_handler (filp=<value optimized out>, buf=0x24808, count=1, ppos=0xc782bf70, 
97
    write=1) at /home/gnutoo/embedded/android/replicant-4.0/kernel/samsung/tuna/fs/proc/proc_sysctl.c:158
98
#6  0xc01741b0 in proc_sys_write (filp=0x288, buf=0x600f0013 <Address 0x600f0013 out of bounds>, count=1, 
99
    ppos=0xc782a000)
100
    at /home/gnutoo/embedded/android/replicant-4.0/kernel/samsung/tuna/fs/proc/proc_sysctl.c:176
101
#7  0xc0126420 in vfs_write (file=0xc73be500, buf=0x24808 "0", count=<value optimized out>, pos=0xc782bf70)
102
    at /home/gnutoo/embedded/android/replicant-4.0/kernel/samsung/tuna/fs/read_write.c:377
103
#8  0xc0126590 in sys_write (fd=<value optimized out>, buf=0x24808 "0", count=1)
104
    at /home/gnutoo/embedded/android/replicant-4.0/kernel/samsung/tuna/fs/read_write.c:429
105
#9  0xc0055a00 in ?? ()
106
Cannot access memory at address 0x0
107
#10 0xc0055a00 in ?? ()
108
Cannot access memory at address 0x0
109
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
110
</pre>
111 5 Denis 'GNUtoo' Carikli
112 10 Denis 'GNUtoo' Carikli
* disable the watchdog timer in the kernel, and recompile it and reflash the boot.img.
113 6 Denis 'GNUtoo' Carikli
114
then open a root console and do:
115
<pre>
116
echo g > /proc/sysrq-trigger
117
</pre>
118 7 Denis 'GNUtoo' Carikli
119
<pre>
120
gnutoo@gnutoo-laptop:~/embedded/android/replicant-4.0$ . build/envsetup.sh 
121
including device/ti/panda/vendorsetup.sh
122
including vendor/replicant/vendorsetup.sh
123
including sdk/bash_completion/adb.bash
124
gnutoo@gnutoo-laptop:~/embedded/android/replicant-4.0$ lunch replicant_maguro-eng
125
126
============================================
127
PLATFORM_VERSION_CODENAME=REL
128
PLATFORM_VERSION=4.0.4
129
TARGET_PRODUCT=replicant_maguro
130
TARGET_BUILD_VARIANT=eng
131
TARGET_BUILD_TYPE=release
132
TARGET_BUILD_APPS=
133
TARGET_ARCH=arm
134
TARGET_ARCH_VARIANT=armv7-a-neon
135
HOST_ARCH=x86
136
HOST_OS=linux
137
HOST_BUILD_TYPE=release
138
BUILD_ID=IMM76L
139
============================================
140
141
142
gnutoo@gnutoo-laptop:~/embedded/android/replicant-4.0$ arm-linux-androideabi-gdb
143
GNU gdb (GDB) 7.1-android-gg2
144
Copyright (C) 2010 Free Software Foundation, Inc.
145
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
146
This is free software: you are free to change and redistribute it.
147
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
148
and "show warranty" for details.
149
This GDB was configured as "--host=i686-linux-gnu --target=arm-elf-linux".
150
For bug reporting instructions, please see:
151
<http://www.gnu.org/software/gdb/bugs/>.
152
(gdb) file /home/gnutoo/embedded/android/replicant-4.0/out/target/product/maguro/obj/KERNEL_OBJ/vmlinux
153
Reading symbols from /home/gnutoo/embedded/android/replicant-4.0/out/target/product/maguro/obj/KERNEL_OBJ/vmlinux...done.
154
(gdb) set remotebaud 115200
155 8 Denis 'GNUtoo' Carikli
(gdb) target remote /dev/ttyUSB0
156
Remote debugging using /dev/ttyUSB0
157
kgdb_breakpoint ()
158
    at /home/gnutoo/embedded/android/replicant-4.0/kernel/samsung/tuna/kernel/debug/debug_core.c:954
159
954		arch_kgdb_breakpoint();
160
(gdb) bt
161
#0  kgdb_breakpoint ()
162
    at /home/gnutoo/embedded/android/replicant-4.0/kernel/samsung/tuna/kernel/debug/debug_core.c:954
163
#1  0xc00df764 in sysrq_handle_dbg (key=-29306880)
164
    at /home/gnutoo/embedded/android/replicant-4.0/kernel/samsung/tuna/kernel/debug/debug_core.c:745
165
#2  0xc02f2e18 in __handle_sysrq (key=103, check_mask=false)
166
    at /home/gnutoo/embedded/android/replicant-4.0/kernel/samsung/tuna/drivers/tty/sysrq.c:522
167
#3  0xc02f2ec4 in write_sysrq_trigger (file=<value optimized out>, buf=<value optimized out>, count=2, 
168
    ppos=0xc4a01f70)
169
    at /home/gnutoo/embedded/android/replicant-4.0/kernel/samsung/tuna/drivers/tty/sysrq.c:870
170
#4  0xc016ba88 in proc_reg_write (file=0xc49ea3c0, buf=0x137fc84 "g\n\f@", count=2, ppos=0xc4a01f70)
171
    at /home/gnutoo/embedded/android/replicant-4.0/kernel/samsung/tuna/fs/proc/inode.c:200
172
#5  0xc0126420 in vfs_write (file=0xc49ea3c0, buf=0x137fc84 "g\n\f@", count=<value optimized out>, 
173
    pos=0xc4a01f70) at /home/gnutoo/embedded/android/replicant-4.0/kernel/samsung/tuna/fs/read_write.c:377
174
#6  0xc0126590 in sys_write (fd=<value optimized out>, buf=0x137fc84 "g\n\f@", count=2)
175
    at /home/gnutoo/embedded/android/replicant-4.0/kernel/samsung/tuna/fs/read_write.c:429
176
#7  0xc0055a00 in ?? ()
177
Cannot access memory at address 0x0
178
#8  0xc0055a00 in ?? ()
179
Cannot access memory at address 0x0
180
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
181
(gdb) 
182 7 Denis 'GNUtoo' Carikli
183
</pre>
184 11 Denis 'GNUtoo' Carikli
185 12 Denis 'GNUtoo' Carikli
h2. Multiplexing the serial port
186
187 11 Denis 'GNUtoo' Carikli
since we have only 1 serial port, you can also use agent proxy to get kgdb and the console at the same time....
188
<pre>
189
git clone git://git.kernel.org/pub/scm/utils/kernel/kgdb/agent-proxy.git
190
cd agent-proxy ; make
191
</pre>
192 12 Denis 'GNUtoo' Carikli
193
h2. Root on serial port
194 13 Denis 'GNUtoo' Carikli
195
* Modify system/su/su.c:
196
<pre>
197
diff --git a/su.c b/su.c
198
index d36eaed..51137d4 100644
199
--- a/su.c
200
+++ b/su.c
201
@@ -494,11 +494,13 @@ int main(int argc, char *argv[])
202
             deny(&ctx);
203
         }
204
 
205
+#if 0
206
         // disallow su in a shell if appropriate
207
         if (ctx.from.uid == AID_SHELL && (atoi(enabled) == 1)) {
208
             LOGE("Root access is disabled by a system setting - enable it under settings -> developer options");
209
             deny(&ctx);
210
         }
211
+#endif
212
     }
213
 
214
     if (ctx.from.uid == AID_ROOT || ctx.from.uid == AID_SHELL)
215
</pre>
216
* adb push it to /system/xbin/su
217
* remove /system/bin/su
218
* chmod +s it: <pre>busybox chmod +s /system/xbin/su</pre>
219 14 Denis 'GNUtoo' Carikli
220
h2. TODO
221 15 Denis 'GNUtoo' Carikli
222 14 Denis 'GNUtoo' Carikli
 * reliable rebugging (right now it breaks on the wrong line)
223
 * phone that doesn't power off screen while debugging...