summaryrefstree
path: root/vendor/bin/init.qcom.early_boot.sh
blob: a6179f365fe8542ab451d1fe5f92581652d16e73 (plain)
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
#! /vendor/bin/sh

# Copyright (c) 2012-2013,2016 The Linux Foundation. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#     * Redistributions of source code must retain the above copyright
#       notice, this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above copyright
#       notice, this list of conditions and the following disclaimer in the
#       documentation and/or other materials provided with the distribution.
#     * Neither the name of The Linux Foundation nor
#       the names of its contributors may be used to endorse or promote
#       products derived from this software without specific prior written
#       permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

export PATH=/vendor/bin

# Set platform variables
if [ -f /sys/devices/soc0/hw_platform ]; then
    soc_hwplatform=`cat /sys/devices/soc0/hw_platform` 2> /dev/null
else
    soc_hwplatform=`cat /sys/devices/system/soc/soc0/hw_platform` 2> /dev/null
fi
if [ -f /sys/devices/soc0/soc_id ]; then
    soc_hwid=`cat /sys/devices/soc0/soc_id` 2> /dev/null
else
    soc_hwid=`cat /sys/devices/system/soc/soc0/id` 2> /dev/null
fi
if [ -f /sys/devices/soc0/platform_version ]; then
    soc_hwver=`cat /sys/devices/soc0/platform_version` 2> /dev/null
else
    soc_hwver=`cat /sys/devices/system/soc/soc0/platform_version` 2> /dev/null
fi

if [ -f /sys/class/graphics/fb0/virtual_size ]; then
    res=`cat /sys/class/graphics/fb0/virtual_size` 2> /dev/null
    fb_width=${res%,*}
fi

bootdevice=`getprop ro.boot.device`

log -t BOOT -p i "MSM target '$1', SoC '$soc_hwplatform', HwID '$soc_hwid', SoC ver '$soc_hwver'"

#For drm based display driver
vbfile=/sys/module/drm/parameters/vblankoffdelay
if [ -w $vbfile ]; then
    echo -1 >  $vbfile
else
    log -t DRM_BOOT -p w "file: '$vbfile' or perms doesn't exist"
fi

function set_density_by_fb() {
    #put default density based on width
    if [ -z $fb_width ]; then
        setprop ro.sf.lcd_density 320
    else
        if [ $fb_width -ge 1440 ]; then
           setprop ro.sf.lcd_density 560
        elif [ $fb_width -ge 1080 ]; then           
         case "$bootdevice" in
            "C1N") #For C1N project, should use 420
                setprop ro.sf.lcd_density 420
                ;;
            "SS2") #For SS2 project, should use 480
                setprop ro.sf.lcd_density 480
                ;;
            "SAT") #For SAT project, should use 480
                setprop ro.sf.lcd_density 480
                ;;
            "SD1") #For SD1 project, should use 480
                setprop ro.sf.lcd_density 480
                ;;
            "PL2") #For PL2 project, should use 420
                setprop ro.sf.lcd_density 420
                ;;
            "B2N") #For B2N project, should use 420
                setprop ro.sf.lcd_density 420
                ;;
            *)
                setprop ro.sf.lcd_density 480
                ;;
         esac
        elif [ $fb_width -ge 720 ]; then
           setprop ro.sf.lcd_density 320 #for 720X1280 resolution
        elif [ $fb_width -ge 640 ]; then
            setprop ro.sf.lcd_density 160 #fihtdc: for 640*480 simu panel
        elif [ $fb_width -ge 480 ]; then
            setprop ro.sf.lcd_density 240 #for 480X854 QRD resolution
        else
            setprop ro.sf.lcd_density 160
        fi
    fi
}
target=`getprop ro.board.platform`
case "$target" in
    "msm7630_surf" | "msm7630_1x" | "msm7630_fusion")
        case "$soc_hwplatform" in
            "FFA" | "SVLTE_FFA")
                # linking to surf_keypad_qwerty.kcm.bin instead of surf_keypad_numeric.kcm.bin so that
                # the UI keyboard works fine.
                ln -s  /system/usr/keychars/surf_keypad_qwerty.kcm.bin /system/usr/keychars/surf_keypad.kcm.bin
                ;;
            "Fluid")
                setprop ro.sf.lcd_density 240
                setprop qcom.bt.dev_power_class 2
                ;;
            *)
                ln -s  /system/usr/keychars/surf_keypad_qwerty.kcm.bin /system/usr/keychars/surf_keypad.kcm.bin
                ;;
        esac
        ;;

    "msm8660")
        case "$soc_hwplatform" in
            "Fluid")
                setprop ro.sf.lcd_density 240
                ;;
            "Dragon")
                setprop ro.sound.alsa "WM8903"
                ;;
        esac
        ;;

    "msm8960")
        # lcd density is write-once. Hence the separate switch case
        case "$soc_hwplatform" in
            "Liquid")
                if [ "$soc_hwver" == "196608" ]; then # version 0x30000 is 3D sku
                    setprop ro.sf.hwrotation 90
                fi

                setprop ro.sf.lcd_density 160
                ;;
            "MTP")
                setprop ro.sf.lcd_density 240
                ;;
            *)
                case "$soc_hwid" in
                    "109")
                        setprop ro.sf.lcd_density 160
                        ;;
                    *)
                        setprop ro.sf.lcd_density 240
                        ;;
                esac
            ;;
        esac

        #Set up composition type based on the target
        case "$soc_hwid" in
            87)
                #8960
                setprop debug.composition.type dyn
                ;;
            153|154|155|156|157|138)
                #8064 V2 PRIME | 8930AB | 8630AB | 8230AB | 8030AB | 8960AB
                setprop debug.composition.type c2d
                ;;
            *)
        esac
        ;;

    "msm8974")
        case "$soc_hwplatform" in
            "Liquid")
                setprop ro.sf.lcd_density 160
                # Liquid do not have hardware navigation keys, so enable
                # Android sw navigation bar
                setprop ro.hw.nav_keys 0
                ;;
            "Dragon")
                setprop ro.sf.lcd_density 240
                ;;
            *)
                setprop ro.sf.lcd_density 320
                ;;
        esac
        ;;

    "msm8226")
        case "$soc_hwplatform" in
            *)
                setprop ro.sf.lcd_density 320
                ;;
        esac
        ;;

    "msm8610" | "apq8084" | "mpq8092")
        case "$soc_hwplatform" in
            *)
                setprop ro.sf.lcd_density 240
                ;;
        esac
        ;;
    "apq8084")
        case "$soc_hwplatform" in
            "Liquid")
                setprop ro.sf.lcd_density 320
                # Liquid do not have hardware navigation keys, so enable
                # Android sw navigation bar
                setprop ro.hw.nav_keys 0
                ;;
            "SBC")
                setprop ro.sf.lcd_density 200
                # SBC do not have hardware navigation keys, so enable
                # Android sw navigation bar
                setprop qemu.hw.mainkeys 0
                ;;
            *)
                setprop ro.sf.lcd_density 480
                ;;
        esac
        ;;
    "msm8996")
        case "$soc_hwplatform" in
            "Dragon")
                setprop ro.sf.lcd_density 240
                setprop qemu.hw.mainkeys 0
                ;;
            "ADP")
                setprop ro.sf.lcd_density 160
                setprop qemu.hw.mainkeys 0
                ;;
            "SBC")
                setprop ro.sf.lcd_density 240
                setprop qemu.hw.mainkeys 0
                ;;
            *)
                setprop ro.sf.lcd_density 560
                ;;
        esac
        ;;
    "msm8937" | "msm8940")
        # Set ro.opengles.version based on chip id.
        # MSM8937 and MSM8940  variants supports OpenGLES 3.1
        # 196608 is decimal for 0x30000 to report version 3.0
        # 196609 is decimal for 0x30001 to report version 3.1
        # 196610 is decimal for 0x30002 to report version 3.2
        case "$soc_hwid" in
            294|295|296|297|298|313)
                setprop ro.opengles.version 196610
                ;;
            303|307|308|309)
                # Vulkan is not supported for 8917 variants
                setprop ro.opengles.version 196608
                setprop persist.graphics.vulkan.disable true
                ;;
            *)
                setprop ro.opengles.version 196608
                ;;
        esac
        ;;
    "msm8909")
        case "$soc_hwplatform" in
            *)
                setprop persist.graphics.vulkan.disable true
                ;;
        esac
        ;;
    "msm8998" | "apq8098_latv")
        case "$soc_hwplatform" in
            *)
                setprop ro.sf.lcd_density 560
                if [ ! -e /dev/kgsl-3d0 ]; then
                    setprop persist.sys.force_sw_gles 1
                    setprop sdm.idle_time 0
                else
                    setprop persist.sys.force_sw_gles 0
                fi
                ;;
        esac
        case "$soc_hwid" in
                "319") #apq8098_latv
                echo "\n==Loading ALX module==\n"
                insmod /system/lib/modules/alx.ko
		;;
	esac
        ;;
    "sdm845")
        case "$soc_hwplatform" in
            *)
                setprop ro.sf.lcd_density 560
                if [ ! -e /dev/kgsl-3d0 ]; then
                    setprop persist.sys.force_sw_gles 1
                    setprop sdm.idle_time 0
                else
                    setprop persist.sys.force_sw_gles 0
                fi
                ;;
        esac
        ;;
    "msm8953")
        cap_ver=`cat /sys/devices/soc/1d00000.qcom,vidc/capability_version` 2> /dev/null
        if [ $cap_ver -eq 1 ]; then
            setprop media.msm8953.version 1
        fi
        ;;
esac

# In mpss AT version is greater than 3.1, need
# to use the new vendor-ril which supports L+L feature
# otherwise use the existing old one.
if [ -f /firmware/verinfo/ver_info.txt ]; then
    modem=`cat /firmware/verinfo/ver_info.txt |
            sed -n 's/^[^:]*modem[^:]*:[[:blank:]]*//p' |
            sed 's/.*AT.\(.*\)/\1/g' | cut -d \- -f 1`
    zygote=`getprop ro.zygote`
    case "$zygote" in
    "zygote64_32")
        if [ "$modem" \< "3.1" ]; then
            setprop vendor.rild.libpath "/vendor/lib64/libril-qc-qmi-1.so"
        else
            setprop vendor.rild.libpath "/vendor/lib64/libril-qc-hal-qmi.so"
        fi
        ;;
    "zygote32")
        if [ "$modem" \< "3.1" ]; then
            setprop vendor.rild.libpath "/vendor/lib/libril-qc-qmi-1.so"
        else
            setprop vendor.rild.libpath "/vendor/lib/libril-qc-hal-qmi.so"
        fi
        ;;
    esac
fi

#set default lcd density
#Since lcd density has read only
#property, it will not overwrite previous set
#property if any target is setting forcefully.
set_density_by_fb

# Setup display nodes & permissions
# HDMI can be fb1 or fb2
# Loop through the sysfs nodes and determine
# the HDMI(dtv panel)

function set_perms() {
    #Usage set_perms <filename> <ownership> <permission>
    chown -h $2 $1
    chmod $3 $1
}

function setHDMIPermission() {
   file=/sys/class/graphics/fb$1
   dev_file=/dev/graphics/fb$1
   dev_gfx_hdmi=/devices/virtual/switch/hdmi

   set_perms $file/hpd system.graphics 0664
   set_perms $file/res_info system.graphics 0664
   set_perms $file/vendor_name system.graphics 0664
   set_perms $file/product_description system.graphics 0664
   set_perms $file/video_mode system.graphics 0664
   set_perms $file/format_3d system.graphics 0664
   set_perms $file/s3d_mode system.graphics 0664
   set_perms $file/dynamic_fps system.graphics 0664
   set_perms $file/msm_fb_dfps_mode system.graphics 0664
   set_perms $file/hdr_stream system.graphics 0664
   set_perms $file/cec/enable system.graphics 0664
   set_perms $file/cec/logical_addr system.graphics 0664
   set_perms $file/cec/rd_msg system.graphics 0664
   set_perms $file/pa system.graphics 0664
   set_perms $file/cec/wr_msg system.graphics 0600
   set_perms $file/hdcp/tp system.graphics 0664
   set_perms $file/hdmi_audio_cb audioserver.audio 0600
   ln -s $dev_file $dev_gfx_hdmi
}

# check for the type of driver FB or DRM
fb_driver=/sys/class/graphics/fb0
if [ -e "$fb_driver" ]
then
    # check for HDMI connection
    for fb_cnt in 0 1 2 3
    do
        file=/sys/class/graphics/fb$fb_cnt/msm_fb_panel_info
        if [ -f "$file" ]
        then
          cat $file | while read line; do
            case "$line" in
                *"is_pluggable"*)
                 case "$line" in
                      *"1"*)
                      setHDMIPermission $fb_cnt
                 esac
            esac
          done
        fi
    done

    # check for mdp caps
    file=/sys/class/graphics/fb0/mdp/caps
    if [ -f "$file" ]
    then
        setprop debug.gralloc.gfx_ubwc_disable 1
        cat $file | while read line; do
          case "$line" in
                    *"ubwc"*)
                    setprop debug.gralloc.enable_fb_ubwc 1
                    setprop debug.gralloc.gfx_ubwc_disable 0
                esac
        done
    fi

    file=/sys/class/graphics/fb0
    if [ -d "$file" ]
    then
            set_perms $file/idle_time system.graphics 0664
            set_perms $file/dynamic_fps system.graphics 0664
            set_perms $file/dyn_pu system.graphics 0664
            set_perms $file/modes system.graphics 0664
            set_perms $file/mode system.graphics 0664
            set_perms $file/msm_cmd_autorefresh_en system.graphics 0664
    fi

    # set lineptr permissions for all displays
    for fb_cnt in 0 1 2 3
    do
        file=/sys/class/graphics/fb$fb_cnt
        if [ -f "$file/lineptr_value" ]; then
            set_perms $file/lineptr_value system.graphics 0664
        fi
        if [ -f "$file/msm_fb_persist_mode" ]; then
            set_perms $file/msm_fb_persist_mode system.graphics 0664
        fi
    done
fi

boot_reason=`cat /proc/sys/kernel/boot_reason`
reboot_reason=`getprop ro.boot.alarmboot`
power_off_alarm_file=`cat /persist/alarm/powerOffAlarmSet`
case "$bootdevice" in
    "SS2" | "SAT" | "SD1")
        # Boot into Android
        setprop ro.alarm_boot false
        ;;
    *)
        # Default Android Flow into Alarm UI
        if [ "$boot_reason" = "3" ] || [ "$reboot_reason" = "true" ]; then
            if [ "$power_off_alarm_file" = "1" ]
            then
                setprop ro.alarm_boot true
                setprop debug.sf.nobootanimation 1
            fi
        else
            setprop ro.alarm_boot false
        fi
        ;;
esac

# copy GPU frequencies to system property
if [ -f /sys/class/kgsl/kgsl-3d0/gpu_available_frequencies ]; then
    gpu_freq=`cat /sys/class/kgsl/kgsl-3d0/gpu_available_frequencies` 2> /dev/null
    setprop ro.gpu.available_frequencies "$gpu_freq"
fi