20230413在CV1826平台配置开机自启动程序
2023/4/13 10:51
1、项目需求:硬件需要测量摄像头开机之后的电压/时钟信号,但是不想每次开机的时候都通过adb连接cv1826来开启摄像头。
C:\Users\Sun>adb shell
/ #
/ # cd /mnt/
/mnt #
/mnt # ls -l
total 28816
drwxr-xr-x 3 root root 4096 Jan 1 00:01 data
drwx------ 2 root root 4096 Jan 1 00:00 lost+found
-rw-rw-rw- 1 root root 24250004 Apr 11 2023 sample_vio
-rw-rw-r-- 1 root root 5242880 Apr 11 2023 secure.img
drwxrwxr-x 2 root root 4096 Apr 11 2023 tmp_secure
/mnt # chmod 777 sample_vio
/mnt #
/mnt # ./sample_vio 0
2、很容易知道:/etc/init.d/rcS脚本会在开机的时候递归执行以大S开头的全部脚本。
Microsoft Windows [版本 10.0.19045.2728]
(c) Microsoft Corporation。保留所有权利。
C:\Users\Sun>adb shell
/ #
/ # cd /etc/init.d/
/etc/init.d #
/etc/init.d # ls -l
total 21
-rwxr-xr-x 1 root root 1630 Mar 28 2023 S01panel
-rwxr-xr-x 1 root root 1012 Apr 13 2023 S01syslogd
-rwxr-xr-x 1 root root 1004 Apr 13 2023 S02klogd
-rwxr-xr-x 1 root root 2804 Apr 13 2023 S02sysctl
-rwxr-xr-x 1 root root 843 Apr 13 2023 S10auto_mount
-rwxr-xr-x 1 root root 1594 Apr 13 2023 S10udev
-rwxr-xr-x 1 root root 1684 Apr 13 2023 S20urandom
-rwxr-xr-x 1 root root 1619 Apr 13 2023 S30dbus
-rwxr-xr-x 1 root root 1001 Apr 13 2023 S40bluetooth
-rwxr-xr-x 1 root root 438 Apr 13 2023 S40network
-rwxr-xr-x 1 root root 452 Mar 28 2023 S98wlan
-rwxr-xr-x 1 root root 563 Mar 28 2023 S99adbd
-rwxr-xr-x 1 root root 578 Mar 28 2023 S99mcu
-rwxr-xr-x 1 root root 423 Apr 13 2023 rcK
-rwxr-xr-x 1 root root 408 Apr 13 2023 rcS
/etc/init.d #
/etc/init.d # cat rcS
#!/bin/sh
# Start all init scripts in /etc/init.d
# executing them in numerical order.
#
for i in /etc/init.d/S??* ;do
# Ignore dangling symlinks (if any).
[ ! -f "$i" ] && continue
case "$i" in
*.sh)
# Source shell script for speed.
(
trap - INT QUIT TSTP
set start
. $i
)
;;
*)
# No sh extension, so fork subprocess.
$i start
;;
esac
done
/etc/init.d #
3、在S99mcu中加入启动摄像头:
Microsoft Windows [版本 10.0.19045.2728]
(c) Microsoft Corporation。保留所有权利。
C:\Users\Sun>adb shell
/ #
/ #
/ # cd /etc/init.d/
/etc/init.d #
/etc/init.d # ls -l
total 21
-rwxr-xr-x 1 root root 1630 Mar 28 2023 S01panel
-rwxr-xr-x 1 root root 1012 Apr 13 2023 S01syslogd
-rwxr-xr-x 1 root root 1004 Apr 13 2023 S02klogd
-rwxr-xr-x 1 root root 2804 Apr 13 2023 S02sysctl
-rwxr-xr-x 1 root root 843 Apr 13 2023 S10auto_mount
-rwxr-xr-x 1 root root 1594 Apr 13 2023 S10udev
-rwxr-xr-x 1 root root 1684 Apr 13 2023 S20urandom
-rwxr-xr-x 1 root root 1619 Apr 13 2023 S30dbus
-rwxr-xr-x 1 root root 1001 Apr 13 2023 S40bluetooth
-rwxr-xr-x 1 root root 438 Apr 13 2023 S40network
-rwxr-xr-x 1 root root 452 Mar 28 2023 S98wlan
-rwxr-xr-x 1 root root 563 Mar 28 2023 S99adbd
-rwxr-xr-x 1 root root 606 Jan 1 00:04 S99mcu
-rwxr-xr-x 1 root root 423 Apr 13 2023 rcK
-rwxr-xr-x 1 root root 408 Apr 13 2023 rcS
/etc/init.d #
/etc/init.d # cat S99mcu
#!/bin/sh
case "$1" in
start)
printf "Starting MCU: "
/usr/bin/cvi_mv_fw;
devmem 0x03000248 32 0x1;
devmem 0x05025020 32 0xC01E02D;
devmem 0x05025018 32 0x8107ffff;
## pmic suspend write sequence
## (0x26, 0x1D); -> 0x05026F04[31:16]
## (0x80, 0x14); -> 0x05026F04[15:0]
## (0x90, 0x10); -> 0x05026F08[31:16]
## (0x91, 0x00); -> 0x05026F08[15:0]
devmem 0x05026F04 32 0x261D8014;
devmem 0x05026F08 32 0x90109100;
devmem 0x05026020 32 0x5;
;;
stop)
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
sleep 10
/mnt/sample_vio 0
exit $?/etc/init.d # reboot
4、确认sample_vio自启动了:
【实测:】30秒钟后,大概60秒钟/一分钟内,摄像头的AVDD/DVDD都有电压了!
Microsoft Windows [版本 10.0.19045.2728]
(c) Microsoft Corporation。保留所有权利。
C:\Users\Sun>adb shell
/ # ps -e
PID USER COMMAND
1 root {linuxrc} init
2 root [kthreadd]
3 root [rcu_gp]
4 root [rcu_par_gp]
5 root [kworker/0:0-eve]
6 root [kworker/0:0H-mm]
7 root [kworker/u2:0-ev]
8 root [mm_percpu_wq]
9 root [ksoftirqd/0]
10 root [rcu_preempt]
11 root [rcu_sched]
12 root [rcu_bh]
13 root [migration/0]
14 root [cpuhp/0]
15 root [kdevtmpfs]
16 root [netns]
17 root [rcu_tasks_kthre]
18 root [kworker/0:1-eve]
19 root [oom_reaper]
20 root [writeback]
21 root [kcompactd0]
22 root [crypto]
23 root [kblockd]
24 root [watchdogd]
25 root [rpciod]
26 root [kworker/u3:0]
27 root [xprtiod]
28 root [cfg80211]
29 root [kswapd0]
30 root [nfsiod]
58 root [irq/178-axp2101]
59 root [irq/97-cviusb-o]
60 root [uas]
61 root [axp2101]
62 root [kworker/0:2]
63 root [kworker/0:3]
64 root [btfwwork]
65 root [irq/41-mmc0]
66 root [irq/42-mmc1]
67 root [ion_system_heap]
68 root [mmc_complete]
69 root [kworker/0:1H-mm]
70 root [ipv6_addrconf]
71 root [krfcommd]
73 root [kworker/u2:1-ev]
78 root [kworker/0:2H-mm]
79 root [jbd2/mmcblk0p5-]
80 root [ext4-rsv-conver]
91 root {rcS} /bin/sh /etc/init.d/rcS
102 root [cvitask_tpu_wor]
119 root /sbin/syslogd -n
123 root /sbin/klogd -n
139 root [jbd2/mmcblk0p7-]
140 root [ext4-rsv-conver]
144 root /sbin/udevd -d
158 root [kworker/0:3H-mm]
170 root [kworker/u2:2-ev]
171 root [kworker/u2:3]
187 dbus dbus-daemon --system
192 root /usr/libexec/bluetooth/bluetoothd -n
267 root [f_mtp]
327 root mtp-server
331 root /usr/bin//adbd
333 root {S99mcu} /bin/sh /etc/init.d/S99mcu start
361 root /bin/sh -
367 root /mnt/sample_vio 0
369 root [cvitask_isp_pre]
370 root [cvitask_isp_pos]
371 root [cvitask_isp_err]
382 root /bin/sh -
384 root /sbin/udevd -d
385 root ps -e
/ #
5、小瑕疵:
如果sample_vio在前台运行,执行reboot,cv1826不会重启。有两种解决方法:
(一)如果您的APP应用程序可以运行在后台,可以使用:
sleep 10
/mnt/sample_vio 0 &
(二)如果您的APP应用程序不能运行在后台,就kill掉之后再reboot
kill -9 367
kill -9 333
333 root {S99mcu} /bin/sh /etc/init.d/S99mcu start
361 root /bin/sh -
367 root /mnt/sample_vio 0
(三)万用解决方法:断电!(拔电池/或者重插TYPE-C接口^_)