Skip to content
This repository was archived by the owner on Feb 14, 2025. It is now read-only.

Commit e1ea00d

Browse files
committed
binder
1 parent 4975679 commit e1ea00d

File tree

3 files changed

+134
-0
lines changed

3 files changed

+134
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
NO.|文件名称|摘要
1414
:--:|:--|:--
15+
0020| [Android_Binder通信](docs/0020_Android_Binder通信.md) | 在树莓派中理解Android Binder通信
1516
0019| [USB_OTG虚拟串口](docs/0019_USB_OTG虚拟串口.md) | USB OTG虚拟串口,可用于学习串口通信
1617
0018| [利用AT24C02_EEPROM理解I2C通信](docs/0018_利用AT24C02_EEPROM理解I2C通信.md) | 利用Overlay加载AT24C02 I2C驱动,通过i2c-tools获取数据
1718
0017| [GPIO中断模式控制网页](docs/0017_GPIO中断模式控制网页.md) | 通过Python3 Flask/websocket作为服务端,使用GPIO控制网页背景

docs/0020_Android_Binder通信.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# Android Binder通信
2+
3+
在树莓派中理解Android Binder通信
4+
5+
## 参考文档
6+
7+
* https://github.com/hungys/binder-for-linux
8+
* [0005_内核编译.md](0005_内核编译.md)
9+
10+
## 内核支持Binder
11+
12+
* make menuconfig
13+
```
14+
.config - Linux/arm 5.4.83 Kernel Configuration
15+
→ Device Drivers → Android ───────────────────────────────────────────────────
16+
┌──────────────────────────────── Android ────────────────────────────────┐
17+
│ Arrow keys navigate the menu. <Enter> selects submenus ---> (or empty │
18+
│ submenus ----). Highlighted letters are hotkeys. Pressing <Y> │
19+
│ includes, <N> excludes, <M> modularizes features. Press <Esc><Esc> to │
20+
│ exit, <?> for Help, </> for Search. Legend: [*] built-in [ ] │
21+
│ ┌─────────────────────────────────────────────────────────────────────┐ │
22+
│ │ [*] Android Drivers │ │
23+
│ │ [*] Android Binder IPC Driver │ │
24+
│ │ [ ] Android Binderfs filesystem │ │
25+
│ │ (binder,hwbinder,vndbinder) Android Binder devices │ │
26+
│ │ [ ] Android Binder IPC Driver Selftest │ │
27+
│ │ │ │
28+
│ │ │ │
29+
│ │ │ │
30+
│ │ │ │
31+
│ └─────────────────────────────────────────────────────────────────────┘ │
32+
├─────────────────────────────────────────────────────────────────────────┤
33+
│ <Select> < Exit > < Help > < Save > < Load > │
34+
└─────────────────────────────────────────────────────────────────────────┘
35+
```
36+
* [Device Drivers] -> [Android]
37+
* KERNEL=kernel7l
38+
* make -j4 zImage
39+
```
40+
scripts/kconfig/conf --syncconfig Kconfig
41+
CALL scripts/atomic/check-atomics.sh
42+
CALL scripts/checksyscalls.sh
43+
CHK include/generated/compile.h
44+
CC drivers/android/binder.o
45+
CC drivers/android/binder_alloc.o
46+
AR drivers/android/built-in.a
47+
AR drivers/staging/android/ion/built-in.a
48+
AR drivers/staging/android/built-in.a
49+
AR drivers/staging/built-in.a
50+
AR drivers/built-in.a
51+
GEN .version
52+
CHK include/generated/compile.h
53+
UPD include/generated/compile.h
54+
CC init/version.o
55+
AR init/built-in.a
56+
LD vmlinux.o
57+
MODPOST vmlinux.o
58+
MODINFO modules.builtin.modinfo
59+
LD .tmp_vmlinux.kallsyms1
60+
KSYM .tmp_vmlinux.kallsyms1.o
61+
LD .tmp_vmlinux.kallsyms2
62+
KSYM .tmp_vmlinux.kallsyms2.o
63+
LD vmlinux
64+
SORTEX vmlinux
65+
SYSMAP System.map
66+
OBJCOPY arch/arm/boot/Image
67+
Kernel: arch/arm/boot/Image is ready
68+
GZIP arch/arm/boot/compressed/piggy_data
69+
AS arch/arm/boot/compressed/piggy.o
70+
LD arch/arm/boot/compressed/vmlinux
71+
OBJCOPY arch/arm/boot/zImage
72+
Kernel: arch/arm/boot/zImage is ready
73+
```
74+
* sudo cp arch/arm/boot/zImage /boot/$KERNEL.img
75+
* sudo sync
76+
* sudo reboot
77+
* ls -al /dev/*binder
78+
```
79+
crw------- 1 root root 10, 61 Mar 5 13:02 /dev/binder
80+
crw------- 1 root root 10, 60 Mar 5 13:02 /dev/hwbinder
81+
crw------- 1 root root 10, 59 Mar 5 13:02 /dev/vndbinder
82+
```
83+
* [Binder示例代码](https://github.com/LowLevelOfLogic/RaspberryPi/tree/servicemanager)
84+
* make
85+
* sudo ./servicemanager
86+
* bctest
87+
* sudo ./bctest publish zengjf
88+
* sudo ./bctest lookup zengjf
89+
* 函数调用:
90+
* sudo ./service
91+
* sudo ./bctest lookup calculate
92+
* sudo ./client a 110
93+
* ![0020_Android_Binder_Communication.png](images/0020_Android_Binder_Communication.png)
94+
95+
## Android中bctest补丁
96+
97+
新的Android版本的bctest没有更新,需要加一些代码才能正常使用
98+
99+
```diff
100+
diff --git a/frameworks/native/cmds/servicemanager/bctest.c b/frameworks/native/cmds/servicemanager/bctest.c
101+
index 354df670e54..782bf29e958 100644
102+
--- a/frameworks/native/cmds/servicemanager/bctest.c
103+
+++ b/frameworks/native/cmds/servicemanager/bctest.c
104+
@@ -16,6 +16,7 @@ uint32_t svcmgr_lookup(struct binder_state *bs, uint32_t target, const char *nam
105+
106+
bio_init(&msg, iodata, sizeof(iodata), 4);
107+
bio_put_uint32(&msg, 0); // strict mode header
108+
+ bio_put_uint32(&msg, 0);
109+
bio_put_string16_x(&msg, SVC_MGR_NAME);
110+
bio_put_string16_x(&msg, name);
111+
112+
@@ -40,6 +41,7 @@ int svcmgr_publish(struct binder_state *bs, uint32_t target, const char *name, v
113+
114+
bio_init(&msg, iodata, sizeof(iodata), 4);
115+
bio_put_uint32(&msg, 0); // strict mode header
116+
+ bio_put_uint32(&msg, 0);
117+
bio_put_string16_x(&msg, SVC_MGR_NAME);
118+
bio_put_string16_x(&msg, name);
119+
bio_put_obj(&msg, ptr);
120+
@@ -93,9 +95,12 @@ int main(int argc, char **argv)
121+
fprintf(stderr,"argument required\n");
122+
return -1;
123+
}
124+
+ fprintf(stderr,"published: [%s]\n", argv[1]);
125+
svcmgr_publish(bs, svcmgr, argv[1], &token);
126+
argc--;
127+
argv++;
128+
+
129+
+ while(1);
130+
} else {
131+
fprintf(stderr,"unknown command %s\n", argv[0]);
132+
return -1;
133+
```
41.1 KB
Loading

0 commit comments

Comments
 (0)