hc
2024-07-02 39af2116d7581c9a12be9e73bb6bdc31496495ef
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/bash -e
### BEGIN INIT INFO
# Provides:          rockchip
# Required-Start:  
# Required-Stop: 
# Default-Start:
# Default-Stop:
# Short-Description: 
# Description:       Setup rockchip platform environment
### END INIT INFO
 
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
 
install_rga() {
    case $1 in
        rk3288|rk3399|rk3399pro|rk3328|px30|rk3326|rk3128|rk3036|rk3566|rk3568)
            RGA=rga
            ;;
        rk3588|rk3588s)
            RGA=rga2
            ;;
    esac
    apt-get install -fy --allow-downgrades /$RGA/*.deb
}
 
install_mali() {
    case $1 in
        rk3288)
            MALI=midgard-t76x-r18p0-r0p0
 
            # 3288w
            cat /sys/devices/platform/*gpu/gpuinfo | grep -q r1p0 && \
                MALI=midgard-t76x-r18p0-r1p0
            ;;
        rk3399|rk3399pro)
            MALI=midgard-t86x-r18p0
            ;;
        rk3328)
            MALI=utgard-450
            ;;
        rk3326|px30)
            MALI=bifrost-g31-g2p0
            ;;
        rk3128|rk3036)
            MALI=utgard-400
            ;;
        rk3568|rk3566)
            MALI=bifrost-g52-g2p0
            ;;
        rk3588|rk3588s)
            MALI=valhall-g610-g6p0
            ;;
    esac
 
    apt-get install -fy --allow-downgrades /libmali-*$MALI*-x11*.deb
}
 
 
function update_npu_fw() {
    /usr/bin/npu-image.sh
    sleep 1
    /usr/bin/npu_transfer_proxy&
}
 
COMPATIBLE=$(cat /proc/device-tree/compatible)
if [[ $COMPATIBLE =~ "rk3288" ]];
then
    CHIPNAME="rk3288"
elif [[ $COMPATIBLE =~ "rk3328" ]]; then
    CHIPNAME="rk3328"
elif [[ $COMPATIBLE =~ "rk3399" && $COMPATIBLE =~ "rk3399pro" ]]; then
    CHIPNAME="rk3399pro"
    update_npu_fw
elif [[ $COMPATIBLE =~ "rk3399" ]]; then
    CHIPNAME="rk3399"
elif [[ $COMPATIBLE =~ "rk3326" ]]; then
    CHIPNAME="rk3326"
elif [[ $COMPATIBLE =~ "px30" ]]; then
    CHIPNAME="px30"
elif [[ $COMPATIBLE =~ "rk3128" ]]; then
    CHIPNAME="rk3128"
elif [[ $COMPATIBLE =~ "rk3566" ]]; then
    CHIPNAME="rk3566"
elif [[ $COMPATIBLE =~ "rk3568" ]]; then
    CHIPNAME="rk3568"
elif [[ $COMPATIBLE =~ "rk3588" ]]; then
    CHIPNAME="rk3588"
else
    CHIPNAME="rk3036"
fi
COMPATIBLE=${COMPATIBLE#rockchip,}
BOARDNAME=${COMPATIBLE%%rockchip,*}
 
# first boot configure
if [ ! -e "/usr/local/first_boot_flag" ] ;
then
    echo "It's the first time booting."
    echo "The rootfs will be configured."
 
    # Force rootfs synced
    mount -o remount,sync /
    #install_mali ${CHIPNAME}
    install_rga ${CHIPNAME}
    setcap CAP_SYS_ADMIN+ep /usr/bin/gst-launch-1.0
    rm -rf /rga*
    rm -rf /*.deb
    rm -rf /lib/firmware/mali_csffw.bin
    mv /etc/resolv.conf  /etc/resolv.conf.bak
    ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
    # The base target does not come with lightdm
    systemctl restart lightdm.service || true
 
    touch /usr/local/first_boot_flag
fi
 
# enable rkwifbt service
#service rkwifibt start
 
# enable async service
#service async start
 
# enable adbd service
#service adbd start
 
# support power management
if [ -e "/usr/sbin/pm-suspend" -a -e /etc/Powermanager ] ;
then
    mv /etc/Powermanager/power-key.sh /usr/bin/
    mv /etc/Powermanager/power-key.conf /etc/triggerhappy/triggers.d/
    if [[ "$CHIPNAME" == "rk3399pro" ]];
    then
        mv /etc/Powermanager/01npu /usr/lib/pm-utils/sleep.d/
        mv /etc/Powermanager/02npu /lib/systemd/system-sleep/
    fi
    mv /etc/Powermanager/triggerhappy /etc/init.d/triggerhappy
 
    rm /etc/Powermanager -rf
    service triggerhappy restart
fi
 
# Create dummy video node for chromium V4L2 VDA/VEA with rkmpp plugin
echo dec > /dev/video-dec0
echo enc > /dev/video-enc0
chmod 660 /dev/video-*
chown root.video /dev/video-*
 
# The chromium using fixed pathes for libv4l2.so
ln -rsf /usr/lib/*/libv4l2.so /usr/lib/
[ -e /usr/lib/aarch64-linux-gnu/ ] && ln -Tsf lib /usr/lib64
 
# sync system time
hwclock --systohc
 
# read mac-address from efuse
# if [ "$BOARDNAME" == "rk3288-miniarm" ]; then
#     MAC=`xxd -s 16 -l 6 -g 1 /sys/bus/nvmem/devices/rockchip-efuse0/nvmem | awk '{print $2$3$4$5$6$7 }'`
#     ifconfig eth0 hw ether $MAC
# fi