20250416在荣品的PRO-RK3566开发板的Android13下编译native C的应用程序的步骤
mm编译的简略步骤以及详细LOG,仅供参考:
rootroot@rootroot-X99-Turbo:~/hailuo_temp/Android13.0$ source build/envsetup.sh
rootroot@rootroot-X99-Turbo:~/hailuo_temp/Android13.0$ lunch
57. rk3566_t-userdebug
Pick from common choices above (e.g. 13) or specify your own (e.g. aosp_barbet-eng): 57
rootroot@rootroot-X99-Turbo:~/hailuo_temp/Android13.0$ cd external/rk3566_tcp_server/
rootroot@rootroot-X99-Turbo:~/hailuo_temp/Android13.0/external/rk3566_tcp_server$ mm
[100% 329/329] Install: out/target/product/rk3566_t/system/bin/rk3566_tcp_server
20250416在荣品的PRO-RK3566开发板的Android13下编译native C的应用程序的步骤
2025/4/16 19:05
缘起:2012年?前后,做freescale的i.MX6Q的Android4.0.4/Andorid4.2.2/Android4.4.2?的时候。
当年为了使用最高的效率来取摄像头的每一帧图像,不能使用APK/JAVA。
最后有人提高了使用native C的应用程序。
现在需要RK3566在Android13下将UART6接收到的的marvlink数据通过UART9/UART3转发出去。115200bps N 8 1。
荣品建议我们参考:Z:\hailuo_temp\Android13.0\external\sc16is752\Android.mk
可以参考这个安卓13 平台 添加对应测试的c 文件的
应用程序 弄好之后 直接使用 mm编译吗?
全局编译就行
已经全局编译了。现在 想单独 编译这个应用程序!
我这边都是全局编译生成的,没有单独编译的方式提供给你哈
Z:\hailuo_temp\Android13.0\external\sc16is752\Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := sc16is752.c
LOCAL_MODULE := sc16is752
LOCAL_MODULE_CLASS := EXECUTABLES
LOCAL_MODULE_OWNER := root
LOCAL_MODULE_GROUP := root
LOCAL_MODULE_SUFFIX :=
include $(BUILD_EXECUTABLE)
修改为:
Z:\hailuo_temp\Android13.0\external\uart6_2_uart3\Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := uart6_2_uart3.c
LOCAL_MODULE := uart6_2_uart3
LOCAL_MODULE_CLASS := EXECUTABLES
LOCAL_MODULE_OWNER := root
LOCAL_MODULE_GROUP := root
LOCAL_MODULE_SUFFIX :=
include $(BUILD_EXECUTABLE)
c_spi_and_i2c_test.patch
commit 57a43916bd5889852ca59d4a1d6d6d27320bf22f
Author: wjy <you@example.com>
Date: Sat Nov 18 10:05:47 2023 +0000
Add spi and i2c test
diff --git a/external/sc16is752/Android.mk b/external/sc16is752/Android.mk
new file mode 100644
index 0000000000..bd112a7621
--- /dev/null
+++ b/external/sc16is752/Android.mk
@@ -0,0 +1,14 @@
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := sc16is752.c
+
+LOCAL_MODULE := sc16is752
+
+LOCAL_MODULE_CLASS := EXECUTABLES
+LOCAL_MODULE_OWNER := root
+LOCAL_MODULE_GROUP := root
+LOCAL_MODULE_SUFFIX :=
+
+include $(BUILD_EXECUTABLE)
+
diff --git a/external/sc16is752/sc16is752.c b/external/sc16is752/sc16is752.c
new file mode 100644
index 0000000000..044bfc6e26
--- /dev/null
+++ b/external/sc16is752/sc16is752.c
@@ -0,0 +1,400 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <linux/i2c-dev.h>
+#include <unistd.h>
+#include <linux/spi/spidev.h>
+#include <time.h>
+#include <getopt.h>
+#include <string.h>
+
+#define CHANNEL_A 0x00
+#define CHANNEL_B 0x01
+
+#define RHR 0x00 // Recv Holding Register
+#define THR 0x00 // Xmit Holding Register
+
+#define IODir 0x0A // I/O P:ins Direction Register
+#define IOState 0x0B // I/O Pins State Register
+#define IOIntEna 0x0C // I/O Interrupt Enable Register
+#define IOCONTROL 0x0E // I/O Pins Control Register
+
+#define IER 0x01 // Interrupt Enable Register
+#define FCR 0x02 // FIFO Control Register in WRITE Mode
+#define IIR 0x02 // Interrupt Identification Register in READ Mode
+
+#define LCR 0x03 // Line Control Register
+#define MCR 0x04 // Modem Control Register
+#define LSR 0x05 // Line status Register
+#define MSR 0x06 // Modem Status Register
+#define SPR 0x07 // ScratchPad Register
+#define TCR 0x06 // Transmission Control Register
+#define TLR 0x07 // Trigger Level Register
+#define TXLVL 0x08 // Xmit FIFO Level Register
+#define RXLVL 0x09 // Recv FIFO Level Register
+#define EFCR 0x0F // Extra Features Control Register
+
+#define DLL 0x00 // Divisor Latch LSB 0x00
+#define DLH 0x01 // Divisor Latch MSB 0x01
+
+#define EFR 0x02
+
+#define FREQ (1843200UL)
+#define BAUDRATE 9600
+
+#define CHANNEL CHANNEL_A
+#define chreg(reg) (reg << 3 | CHANNEL)
+
+typedef unsigned char u8;
+
+#define I2C 0x11
+#define SPI 0x22
+
+// 设备路径
+char *device;
+
+// 片选脚
+char *cs = "/proc/rp_gpio/gpio4c5";
+
+// 测试字符串
+char *tx = "spi or i2c test string";
+
+// 设备类型
+u8 type;
+
+// i2c 设备地址
+u8 addr = 0x4d;
+
+
+u8 read_reg(u8 reg);
+void open_dev();
+void write_reg(u8 reg, u8 val);
+void gpio_set(int val);
+
+int fd = -1;
+int fd_gpio = -1;
+
+
+struct timespec delay = {
+ .tv_sec = 0,
+ .tv_nsec = 100000
+};
+
+
+
+static inline u8 available_data()
+{
+ return read_reg(RXLVL);
+
+}
+
+void write_byte(u8 val)
+{
+ u8 lsr;
+
+ do{
+ lsr = read_reg(LSR);
+ }while((lsr & 0x20) == 0);
+
+ write_reg(THR, val);
+}
+
+u8 read_byte()
+{
+ return read_reg(RHR);;
+}
+
+void test_connect()
+{
+ u8 val;
+ write_reg(SPR, 0x77);
+ if((val = read_reg(SPR)) != 0x77){
+ printf("0x%02x != 0x77\n", val);
+ printf("connect failed\n");
+ exit(-1);
+ }
+
+ write_reg(SPR, 0x99);
+ if((val = read_reg(SPR)) != 0x99){
+ printf("0x%02x != 0x99\n", val);
+ printf("connect failed\n");
+ exit(-2);
+ }
+
+ printf("connect okay\n");
+}
+
+
+u8 read_reg(u8 reg)
+{
+ reg = chreg(reg);
+ unsigned char val[2];
+
+
+ if(type == I2C){
+ if (write(fd, ®, 1) != 1) {
+ perror("write failed");
+ exit(-3);
+ }
+
+ if (read(fd, &val[1], 1) != 1) {
+ perror("read failed");
+ exit(-4);
+ }
+ } else {
+ u8 buf[] = {0x80 | reg, 0xff};
+ struct spi_ioc_transfer tr = {
+ .tx_buf = (unsigned long)buf,
+ .rx_buf = (unsigned long)val,
+ .len = 2,
+ .delay_usecs = 10,
+ .bits_per_word = 8,
+ };
+
+
+ if(ioctl(fd, SPI_IOC_MESSAGE(1), &tr) < 0){
+ perror("ioctl failed");
+ exit(-5);
+ }
+ }
+
+ return val[1];
+}
+
+void write_reg(u8 reg, u8 val)
+{
+ reg = chreg(reg);
+ u8 buf[] = {reg, val};
+
+ if(type == I2C){
+ if (write(fd, buf, 2) != 2) {
+ perror("Failed to write to the i2c bus.");
+ exit(-6);
+ }
+ } else {
+ struct spi_ioc_transfer tr = {
+ .tx_buf = (unsigned long)buf,
+ // .rx_buf = (unsigned long)rxval,
+ .len = 2,
+ };
+
+ if(ioctl(fd, SPI_IOC_MESSAGE(1), &tr) < 0){
+ perror("ioctl failed");
+ exit(-7);
+ }
+ }
+}
+
+
+void set_baudrate()
+{
+ int prescale = 4;
+ u8 lcr;
+ unsigned int div;
+
+ if((read_reg(MCR) & 0x80) == 0)
+ prescale = 1;
+
+ div = (FREQ / prescale) / (BAUDRATE * 16);
+
+ lcr = read_reg(LCR);
+ lcr |= 0x80;
+ write_reg(LCR, lcr);
+
+ write_reg(DLL, (u8)div);
+ write_reg(DLH, (u8)(div >> 8));
+
+ lcr &= 0x7f;
+ write_reg(LCR, lcr);
+}
+
+void set_line()
+{
+ u8 lcr;
+
+ lcr = read_reg(LCR);
+ lcr &= 0xC0;
+
+ lcr |= 0x03;
+
+ write_reg(LCR, lcr);
+}
+
+
+void reset()
+{
+ write_reg(IER, 0x0);
+ write_reg(IIR, 0x1);
+ write_reg(FCR, 0x0);
+ write_reg(LCR, 0x1d);
+ write_reg(MCR, 0x0);
+ write_reg(TCR, 0x0);
+ write_reg(TLR, 0x0);
+ write_reg(EFCR, 0x0);
+ read_reg(RHR);
+}
+
+void fifo_en()
+{
+ u8 fcr;
+
+ fcr = read_reg(FCR);
+ fcr |= 0x01;
+ write_reg(FCR, fcr);
+
+}
+void fifo_reset()
+{
+ u8 fcr;
+
+ fcr = read_reg(FCR);
+ fcr |= 0x06;
+ write_reg(FCR, fcr);
+}
+
+void init()
+{
+ fifo_en();
+ fifo_reset();
+ set_baudrate();
+ set_line();
+}
+
+void write_bytes(char *buf, size_t len)
+{
+ for(int i = 0; i < len; i ++){
+ write_byte(buf[i]);
+ }
+}
+
+void loop()
+{
+ size_t len = strlen(tx);
+
+ write_bytes(tx, len);
+ while(available_data() > 0){
+ printf("%c", read_byte());
+ }
+ printf("\n");
+}
+
+void open_dev()
+{
+
+ if(type == I2C){
+ if ((fd = open(device, O_RDWR)) < 0) {
+ perror("open bus failed\n");
+ exit(-8);
+ }
+
+ if (ioctl(fd, I2C_SLAVE, addr) < 0) {
+ close(fd);
+ perror("failed access i2c dev\n");
+ exit(-9);
+ }
+
+ }else {
+ if ((fd = open(device, O_RDWR)) < 0) {
+ perror("open bus failed");
+ close(fd_gpio);
+ exit(-10);
+ }
+
+ u8 mode = SPI_MODE_0;
+ if (ioctl(fd, SPI_IOC_WR_MODE, &mode) < 0) {
+ perror("Error setting SPI mode");
+ close(fd);
+ close(fd_gpio);
+ exit(-11);
+ }
+
+ }
+}
+
+
+void usage()
+{
+ puts("usage:");
+ puts("-d device, such as /dev/spidev0.0 or /dev/i2c-4\n"
+ "-s string, default is \"spi or i2c test string\"\n"
+ "\nexample:\n"
+ "./sc16is752 -d /dev/spidev0.0 -c /proc/rp_gpio/gpio4c5 -s \"TestString\"\n"
+ "./sc16is752 -d /dev/i2c-4 -s \"TestString\"\n");
+
+ exit(-12);
+}
+
+void parse_cmd(int argc, char *argv[])
+{
+ static const struct option lopts[] = {
+ {"device", 1, 0, 'd'}, // 设备节点
+ {"tx", 1, 0, 's'}, // 传输的字符串
+ {"cs", 1, 0, 'c'}, // SPI 设备所使用的片选脚
+ {NULL, 0, 0, 0}
+ };
+
+
+ while(1){
+ int c = getopt_long(argc, argv,
+ "D:c:s:d:b:i:o:vS:I:",
+ lopts, NULL);
+ if(c == -1)
+ break;
+
+ switch(c){
+ case 'd':
+ device = optarg;
+ break;
+ case 'c':
+ cs = optarg;
+ break;
+ case 's':
+ tx = optarg;
+ break;
+ default:
+ usage();
+ }
+ }
+
+ if(device == NULL){
+ printf("device is null\n");
+ exit(-13);
+ }
+
+ if(strstr(device, "i2c") != NULL)
+ type = I2C;
+ else if(strstr(device, "spi") != NULL)
+ type = SPI;
+ else {
+ printf("no i2c or spi device\n");
+ exit(-14);
+ }
+
+/* if(type == SPI && cs == NULL){
+ printf("spi must set gpio pin\n");
+ exit(-1);
+ }
+ */
+}
+
+
+int main(int argc, char *argv[])
+{
+
+ parse_cmd(argc, argv);
+ open_dev();
+
+ reset();
+
+ test_connect();
+
+ init();
+
+ loop();
+
+ close(fd);
+
+ return 0;
+}
+
diff --git a/vendor/rockchip/common/apps/DeviceTest/DeviceTest.apk b/vendor/rockchip/common/apps/DeviceTest/DeviceTest.apk
index b8149a8368..015cfb80a8 100755
Binary files a/vendor/rockchip/common/apps/DeviceTest/DeviceTest.apk and b/vendor/rockchip/common/apps/DeviceTest/DeviceTest.apk differ
完整的编译LOG:
rootroot@rootroot-X99-Turbo:~/hailuo_temp/Android13.0$ source build/envsetup.sh
rootroot@rootroot-X99-Turbo:~/hailuo_temp/Android13.0$
rootroot@rootroot-X99-Turbo:~/hailuo_temp/Android13.0$ lunch
You're building on Linux
Lunch menu .. Here are the common combinations:
1. PX30_t-user
2. PX30_t-userdebug
3. aosp_arm-eng
4. aosp_arm64-eng
5. aosp_bluejay_car-userdebug
6. aosp_bramble_car-userdebug
7. aosp_cf_arm64_auto-userdebug
8. aosp_cf_arm64_phone-userdebug
9. aosp_cf_x86_64_foldable-userdebug
10. aosp_cf_x86_64_only_phone_hsum-userdebug
11. aosp_cf_x86_64_pc-userdebug
12. aosp_cf_x86_64_phone-userdebug
13. aosp_cf_x86_64_tv-userdebug
14. aosp_cf_x86_auto-userdebug
15. aosp_cf_x86_phone-userdebug
16. aosp_cf_x86_tv-userdebug
17. aosp_coral_car-userdebug
18. aosp_flame_car-userdebug
19. aosp_oriole-userdebug
20. aosp_oriole_car-userdebug
21. aosp_raven-userdebug
22. aosp_raven_car-userdebug
23. aosp_redfin_car-userdebug
24. aosp_slider-userdebug
25. aosp_sunfish_car-userdebug
26. aosp_whitefin-userdebug
27. aosp_x86-eng
28. aosp_x86_64-eng
29. arm_krait-eng
30. arm_v7_v8-eng
31. armv8-eng
32. armv8_cortex_a55-eng
33. armv8_kryo385-eng
34. beagle_x15-userdebug
35. beagle_x15_auto-userdebug
36. hikey-userdebug
37. hikey64_only-userdebug
38. hikey960-userdebug
39. hikey960_tv-userdebug
40. hikey_tv-userdebug
41. qemu_trusty_arm64-userdebug
42. rk3326_t-user
43. rk3326_t-userdebug
44. rk3326_tgo-user
45. rk3326_tgo-userdebug
46. rk3399_t-user
47. rk3399_t-userdebug
48. rk3528_box-user
49. rk3528_box-userdebug
50. rk3562_32bit-user
51. rk3562_32bit-userdebug
52. rk3562_t-user
53. rk3562_t-userdebug
54. rk3562_tgo-user
55. rk3562_tgo-userdebug
56. rk3566_t-user
57. rk3566_t-userdebug
58. rk3566_tgo-user
59. rk3566_tgo-userdebug
60. rk3568_t-user
61. rk3568_t-userdebug
62. rk3588_box-user
63. rk3588_box-userdebug
64. rk3588_s-user
65. rk3588_s-userdebug
66. rk3588_t-user
67. rk3588_t-userdebug
68. rk3588_xr-user
69. rk3588_xr-userdebug
70. rk3588m_car-user
71. rk3588m_car-userdebug
72. rk3588m_s-user
73. rk3588m_s-userdebug
74. rk3588s_s-user
75. rk3588s_s-userdebug
76. rk3588s_t-user
77. rk3588s_t-userdebug
78. sdk_car_arm-userdebug
79. sdk_car_arm64-userdebug
80. sdk_car_portrait_x86_64-userdebug
81. sdk_car_x86-userdebug
82. sdk_car_x86_64-userdebug
83. sdk_pc_x86_64-userdebug
84. silvermont-eng
85. uml-userdebug
86. yukawa-userdebug
87. yukawa_sei510-userdebug
Which would you like? [aosp_arm-eng]
Pick from common choices above (e.g. 13) or specify your own (e.g. aosp_barbet-eng): 57
Hint: next time you can simply run 'lunch rk3566_t-userdebug'
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=13
TARGET_PRODUCT=rk3566_t
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm64
TARGET_ARCH_VARIANT=armv8-a
TARGET_CPU_VARIANT=cortex-a55
TARGET_2ND_ARCH=arm
TARGET_2ND_ARCH_VARIANT=armv8-2a
TARGET_2ND_CPU_VARIANT=cortex-a55
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-5.15.0-131-generic-x86_64-Ubuntu-20.04.6-LTS
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=TQ3C.230805.001.B2
OUT_DIR=out
============================================
rootroot@rootroot-X99-Turbo:~/hailuo_temp/Android13.0$
rootroot@rootroot-X99-Turbo:~/hailuo_temp/Android13.0$ cd external/rk3566_tcp_server/
rootroot@rootroot-X99-Turbo:~/hailuo_temp/Android13.0/external/rk3566_tcp_server$
rootroot@rootroot-X99-Turbo:~/hailuo_temp/Android13.0/external/rk3566_tcp_server$ ll
total 92
drwx------ 2 rootroot rootroot 4096 4月 15 09:26 ./
drwxrwxr-x 388 rootroot rootroot 12288 4月 15 09:26 ../
-rwx------ 1 rootroot rootroot 270 4月 10 18:20 Android.mk*
-rwx------ 1 rootroot rootroot 30841 4月 10 18:16 rk3566_tcp_server_0410.c*
-rwx------ 1 rootroot rootroot 32346 4月 11 18:10 rk3566_tcp_server.c*
-rwx------ 1 rootroot rootroot 7228 2月 27 09:52 sc16is752.c*
rootroot@rootroot-X99-Turbo:~/hailuo_temp/Android13.0/external/rk3566_tcp_server$
rootroot@rootroot-X99-Turbo:~/hailuo_temp/Android13.0/external/rk3566_tcp_server$ mm
build/make/core/soong_config.mk:209: warning: BOARD_PLAT_PUBLIC_SEPOLICY_DIR has been deprecated. Use SYSTEM_EXT_PUBLIC_SEPOLICY_DIRS instead.
build/make/core/soong_config.mk:210: warning: BOARD_PLAT_PRIVATE_SEPOLICY_DIR has been deprecated. Use SYSTEM_EXT_PRIVATE_SEPOLICY_DIRS instead.
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=13
TARGET_PRODUCT=rk3566_t
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_ARCH=arm64
TARGET_ARCH_VARIANT=armv8-a
TARGET_CPU_VARIANT=cortex-a55
TARGET_2ND_ARCH=arm
TARGET_2ND_ARCH_VARIANT=armv8-2a
TARGET_2ND_CPU_VARIANT=cortex-a55
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-5.15.0-131-generic-x86_64-Ubuntu-20.04.6-LTS
HOST_CROSS_OS=windows
HOST_CROSS_ARCH=x86
HOST_CROSS_2ND_ARCH=x86_64
HOST_BUILD_TYPE=release
BUILD_ID=TQ3C.230805.001.B2
OUT_DIR=out
============================================
device/rockchip/rk356x/rk3566_t/preinstall/preinstall.mk was modified, regenerating...
device/rockchip/rk356x/rk3566_t/preinstall_del_forever/preinstall.mk was modified, regenerating...
[100% 47/47] initializing build system ...
device/rockchip/common/prebuild.mk:2: warning: Generating manifest snapshot at out/commit_id.xml...
device/rockchip/common/prebuild.mk:3: warning: You can disable this by removing this and setting BOARD_RECORD_COMMIT_ID := false in BoardConfig.mk
[ 16% 53/324] including build/make/target/board/Android.mk ...
build fstab file with device/rockchip/common/scripts/fstab_tools/fstab.in....
rebuilding dtbo image with device/rockchip/rk356x/rk3566_t/dt-overlay.in....
build parameter.txt with device/rockchip/common/scripts/parameter_tools/parameter.in....
[ 25% 82/324] including device/rockchip/rk356x/Android.mk ...
device/rockchip/rk356x/rk3566_t/preinstall_del_forever/weixin8056android2800_0x2800383c_arm64/Android.mk:199: warning: MY_APP_LIB_PATH=out/target/product/rk3566_t/odm/bundled_uninstall_gone-app/weixin805
6android2800_0x2800383c_arm64/lib/arm64
[ 35% 115/324] including external/rk_tee_user/v2/Android.mk ...
'building rk_tee_user v2'
[ 56% 184/324] including hardware/rockchip/audio/Android.mk ...
"BUILD_BISTREAM_TEST"
[ 57% 186/324] including hardware/rockchip/camera_engine_rkisp/Android.mk ...
TARGET_BOARD_PLATFORM=rk356x
[ 73% 238/324] including system/sepolicy/Android.mk ...
system/sepolicy/Android.mk:57: warning: BOARD_PLAT_PUBLIC_SEPOLICY_DIR has been deprecated. Use SYSTEM_EXT_PUBLIC_SEPOLICY_DIRS instead.
system/sepolicy/Android.mk:62: warning: BOARD_PLAT_PRIVATE_SEPOLICY_DIR has been deprecated. Use SYSTEM_EXT_PRIVATE_SEPOLICY_DIRS instead.
[100% 324/324] writing build rules ...
build/make/core/Makefile:72: warning: overriding commands for target `out/target/product/rk3566_t/vendor/lib64/libril.so'
build/make/core/base_rules.mk:533: warning: ignoring old commands for target `out/target/product/rk3566_t/vendor/lib64/libril.so'
build/make/core/Makefile:72: warning: overriding commands for target `out/target/product/rk3566_t/system/bin/uart2tcp'
build/make/core/base_rules.mk:533: warning: ignoring old commands for target `out/target/product/rk3566_t/system/bin/uart2tcp'
[100% 329/329] Install: out/target/product/rk3566_t/system/bin/rk3566_tcp_server
#### build completed successfully (02:18 (mm:ss)) ####
rootroot@rootroot-X99-Turbo:~/hailuo_temp/Android13.0/external/rk3566_tcp_server$