android添加自启动程序
然后整体编译烧录或者使用mm命令push到板子上就可以了。
·
我的平台是安卓11的,首先在源码目录下的device/rockchip/rk356x/sbc_rk3568,添加一个目录我这添加了一个can_start目录,这个sbc_rk3568是我添加的工程目录,然后天在can_start目录下下添加Android.mk,内容如下:
diff --git a/sbc_rk3568/can_start/Android.mk b/sbc_rk3568/can_start/Android.mk
new file mode 100644
index 0000000..e204db6
--- /dev/null
+++ b/sbc_rk3568/can_start/Android.mk
@@ -0,0 +1,15 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := main.cpp
+LOCAL_MODULE := can_start
+LOCAL_MODULE_TAGS := optional
+#LOCAL_C_INCLUDES := $(LOCAL_PATH)/include/
+#LOCAL_CFLAGS := -O2 -g -W -Wall
+LOCAL_SHARED_LIBRARIES := \
+ libcutils \
+ liblog
+
+include $(BUILD_EXECUTABLE)
- 添加cpp文件,内容如下
diff --git a/sbc_rk3568/can_start/main.cpp b/sbc_rk3568/can_start/main.cpp
new file mode 100644
index 0000000..5a90e95
--- /dev/null
+++ b/sbc_rk3568/can_start/main.cpp
@@ -0,0 +1,30 @@
+#include <netdb.h>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <dirent.h>
+
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <utils/Log.h>
+
+
+
+int main()
+{
+ ALOGD("%s: can start 1",__FUNCTION__);
+ system("su root ip link set can0 type can bitrate 20000");
+ ALOGD("%s: can start 2",__FUNCTION__);
+ system("su root ifconfig can0 up");
+
+ ALOGD("%s: can start 1",__FUNCTION__);
+ system("su root ip link set can1 type can bitrate 20000");
+ ALOGD("%s: can start 2",__FUNCTION__);
+ system("su root ifconfig can1 up");
+
+ ALOGD("%s: can start 5",__FUNCTION__);
+
+ return 0;
+}
- 再修改xx.mk,将应用程序添加编进系统里
diff --git a/sbc_rk3568/sbc_rk3568.mk b/sbc_rk3568/sbc_rk3568.mk
index 9a779cd..8e58644 100644
--- a/sbc_rk3568/sbc_rk3568.mk
+++ b/sbc_rk3568/sbc_rk3568.mk
@@ -65,7 +65,8 @@ PRODUCT_PACKAGES += eepromtool \
log2long \
slcanpty \
slcand \
- slcan_attach
+ slcan_attach \
+ can_start
- 修改*.rc文件
diff --git a/init.rockchip.rc b/init.rockchip.rc
index 4f80547..89d0cde 100755
--- a/init.rockchip.rc
+++ b/init.rockchip.rc
@@ -16,6 +16,7 @@ on post-fs
on boot
setprop UserVolumeLabel "RockChips"
+ start CanStart
service charger /system/bin/charger
class charger
@@ -87,6 +88,12 @@ service iprenew_bt-pan /system/bin/dhcpcd -n
disabled
oneshot
+service CanStart /system/bin/can_start
+ class core
+ disabled
+ oneshot
+
+
# Only mount debugfs on userdebug build
on property:ro.debuggable=1
mount debugfs /sys/kernel/debug /sys/kernel/debug mode=755
- 添加权限:
diff --git a/sepolicy/vendor/CanStart.te b/sepolicy/vendor/CanStart.te
new file mode 100644
index 0000000..537cb11
--- /dev/null
+++ b/sepolicy/vendor/CanStart.te
@@ -0,0 +1,4 @@
+type CanStart, domain, coredomain;
+type CanStart_exec, exec_type, file_type, system_file_type;
+init_daemon_domain(CanStart)
+
diff --git a/sepolicy/vendor/file_contexts b/sepolicy/vendor/file_contexts
index bc030c8..4a03335 100644
--- a/sepolicy/vendor/file_contexts
+++ b/sepolicy/vendor/file_contexts
@@ -230,3 +230,4 @@
/vendor/bin/flash_img.sh u:object_r:vendor_install_recovery_exec:s0
# vibrator aidl
/(vendor|system/vendor)/bin/hw/android\.hardware\.vibrator-service\.rockchip u:object_r:hal_vibrator_default_exec:s0
+/system/bin/can_start u:object_r:CanStart_exec:s0
然后整体编译烧录或者使用mm命令push到板子上就可以了
更多推荐
已为社区贡献5条内容
所有评论(0)