summaryrefslogtreecommitdiff
path: root/android-tools/x15/flash.sh
blob: 1f1fd7e5dd4a20af4e90df0b5d540e956150e99a (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
#!/bin/bash -ex
# https://wiki-archive.linaro.org/Boards/BeagleBoard-X15
# https://linaro.atlassian.net/wiki/spaces/CTT/pages/25111140766/BeagleBoard+X15

local_android_serial="0e005017394200e2"
local_android_product="am57xx_evm_reva3"

if adb devices|grep ${local_android_serial}; then
    adb -s ${local_android_serial} reboot bootloader
    sleep 5
    fastboot devices
    sleep 3
fi
num_fastboot_devices=$(fastboot devices|wc -l)
if [ ${num_fastboot_devices} -eq 0 ]; then
    echo "No fastboot devices available, please check and try again"
    export ANDROID_SERIAL="${local_android_serial}"
elif [ ${num_fastboot_devices} -ne 1 ] && [ -z "${ANDROID_SERIAL}" ]; then
    # for local multiple devices support
    export ANDROID_SERIAL="${local_android_serial}"
elif [ ${num_fastboot_devices} -eq 1 ] && [ -z "${ANDROID_SERIAL}" ]; then
    device_serial=$(fastboot devices|awk '{print $1}')
    export ANDROID_SERIAL="${device_serial}"
fi

product=$(fastboot getvar product 2>&1 |grep product|awk '{print $2}')
if [ "X${product}" != "X${local_android_product}" ]; then
    echo "This is not a ${local_android_product} board: ${product}"
    exit 1
fi
# echo 0x10 >/sys/module/drm/parameters/debug
#    Bit 0 (0x01)  will enable CORE messages (drm core code)
#    Bit 1 (0x02)  will enable DRIVER messages (drm controller code)
#    Bit 2 (0x04)  will enable KMS messages (modesetting code)
#    Bit 3 (0x08)  will enable PRIME messages (prime code)
#    Bit 4 (0x10)  will enable ATOMIC messages (atomic code)
#    Bit 5 (0x20)  will enable VBL messages (vblank code)
#    Bit 7 (0x80)  will enable LEASE messages (leasing code)
#    Bit 8 (0x100) will enable DP messages (displayport code)
#    module_param_named(debug, drm_debug, int, 0600);
#    drivers/gpu/drm/drm_drv.c
#
# echo 8 > /proc/sys/kernel/printk
# The first value in our output is the current console_loglevel. This is the information we were looking for: the value, 4 in this case, represents the log level currently used. As said before this means that only messages adopting a severity level higher than it, will be displayed on the console.
# The second value in the output represents the default_message_loglevel. This value is automatically used for messages without a specific log level: if a message is not associated with a log level, this one will be used for it.
# The third value in the output reports the minimum_console_loglevel status. It indicates the minimum loglevel which can be used for console_loglevel. The level here used it’s 1, the highest.
# Finally, the last value represents the default_console_loglevel, which is the default loglevel used for console_loglevel at boot time.

img_dir=${1}
if [ -z "${img_dir}" ]; then
    img_dir="out/target/product/beagle_x15"
fi
#if [ ! -d "${img_dir}" ]; then
#    img_dir="out/target/product/beagle_x15"
#fi

#if ! [ -d ${img_dir} ]; then
#    echo "The specified path is not a directory:${img_dir}"
#    exit 1
#fi

function flash_image(){
    local partition=$1
    local file_img=$2
    if [ -z "${partition}" ] || [ -z "${file_img}" ]; then
        return
    fi
    temp_file=false
    if echo "${file_img}"|grep -E "^http://|^https://"; then
        f_img_local=$(mktemp -u "/tmp/${partition}-XXX.img")
        ## + wget -c http://192.168.1.14:8000/android/lkft/lkft-aosp-main-db845c/1662/images//cache.img --progress=dot:mega -O /tmp/cache-GNu.img
        ## --2023-10-19 14:08:42--  http://192.168.1.14:8000/android/lkft/lkft-aosp-main-db845c/1662/images//cache.img
        ## Connecting to 192.168.1.14:8000... connected.
        ## HTTP request sent, awaiting response... 404 File not found
        ## 2023-10-19 14:08:42 ERROR 404: File not found.
        is_xz_file=false
        if wget --spider "${file_img}"; then
            cmd_wget="wget -c ${file_img} --progress=dot:giga -O ${f_img_local}"
        elif wget --spider "${file_img}.xz"; then
            cmd_wget="wget -c ${file_img}.xz --progress=dot:giga -O ${f_img_local}.xz"
            is_xz_file=true
        else
            echo "Neither ${file_img} nor ${file_img}.xz exists"
            return
        fi
        if ${cmd_wget}; then
            ${is_xz_file} && xz -d "${f_img_local}.xz"
            file_img="${f_img_local}"
            temp_file=true
        else
            rm -f "${f_img_local}"
            return
        fi
    fi

    if [ -f "${file_img}" ]; then
        :
    elif [ -f "${file_img}.xz" ]; then
        f_img_local=$(mktemp -u "/tmp/${partition}-XXX.img")
        if xz -c -d "${file_img}.xz" >"${f_img_local}"; then
            temp_file=true
            file_img="${f_img_local}"
        else
            return
        fi
    else
        echo "Neither ${file_img} nor ${file_img}.xz exists"
        return
    fi

    echo "======= Flash ${partition} partition with file $file_img =============="
    #/SATA3/nougat/out/host/linux-x86/bin/fastboot flash -w ${partition} ${file_img}
    fastboot flash ${partition} ${file_img}
    if [ $? -ne 0 ]; then
        echo "Failed to deploy ${file_img}"
        exit 1
    elif ${temp_file}; then
        rm ${file_img}
    fi
    # sleep 2 after flash
    sleep 2
}

#fastboot erase environment
#fastboot oem format
#flash_image xloader ${img_dir}/MLO
#flash_image bootloader ${img_dir}/u-boot.img
#flash_image environment ${img_dir}/am57xx-evm-reva3.dtb
#flash_image recovery ${img_dir}/recovery.img
#flash_image boot ${img_dir}/boot.img
flash_image boot_a ${img_dir}/boot.img
flash_image boot_b ${img_dir}/boot.img
## NOTE: falsh of the dtbo_a/b partitions would cause the board failed to boot
## and need to reflash the u-boot to recover
#flash_image dtbo_a ${img_dir}/dtbo.img
#flash_image dtbo_b ${img_dir}/dtbo.img
flash_image vbmeta_a ${img_dir}/vbmeta.img
flash_image vbmeta_b ${img_dir}/vbmeta.img
flash_image recovery ${img_dir}/recovery.img
flash_image super ${img_dir}/super.img
flash_image userdata ${img_dir}/userdata.img
# format would cause error of "FAILED (remote: failed to set partition)"
fastboot erase metadata
fastboot erase misc
sleep 5
fastboot reboot
sleep 5
fastboot reboot

exit 0

reset or fastboot reboot
=> fastboot 0 # operate on sdcard?
$ fastboot flash xloader MLO # flash MLO to the partition
$ fastboot flash bootloader u-boot.img # flash u-boot.img to the partition
$ fastboot reboot
=> env default -f -a # load the all the defined environments
=> setenv partitions $partitions_android # set partitions environment with the value in partitions_android environment
=> env save # save change on partitions environment
=> fastboot 1 # boot from emmc
$ fastboot oem format # recreate the parititons again
$ fastboot flash boot boot_fit.img # flash other images
$ fastboot flash recovery recovery.img
$ fastboot flash vendor vendor.img
$ fastboot flash system system.img
$ fastboot flash userdata userdata.img
$ fastboot reboot
=> setenv bootargs "androidboot.serialno=${serial#} console=ttyS2,115200 androidboot.console=ttyS2 androidboot.hardware=beagle_x15board"
=> setenv bootargs "androidboot.serialno=${serial#} console=ttyS2,115200 androidboot.console=ttyS2 androidboot.hardware=am57xevmboard"
=> run findfdt
=> run emmc_android_boot
=> part list mmc 1 # list partitions for mmc 1

####
fastboot flash boot_a boot.img
fastboot flash boot_b boot.img
fastboot flash dtbo_a dtbo.img
fastboot flash dtbo_b dtbo.img
fastboot flash vbmeta_a vbmeta.img
fastboot flash vbmeta_b vbmeta.img
fastboot flash recovery recovery.img
fastboot flash super super.img
fastboot flash userdata userdata.img
fastboot erase metadata
fastboot erase misc
fastboot reboot

# "card voltage select 0" usually means loose connection
# erase emmc:
=> mmc dev 1 0
=> mmc rescan
=> mmc erase 0 0x400
=> mmc erase 0 0x4000
=> mmc erase 0 0x40000
=> mmc erase 0 0x400000
# mmc dev 0 is sdcard
# dev 1 is emmc .