blob: 17b14bbb944c0d66506ae305e2184da5bf75ea40 (
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
|
#!/system/bin/sh
#
# Install the recovery image
#
# Copyright (c) 2018 by BlackBerry Limited. All Rights Reserved.
# BlackBerry Limited does not grant any rights,
# including the accompanying associated documentation,
# (the Software) for any purpose whatsoever, including without limitation
# any rights to copy, use or distribute the Software. Your rights to use the
# Software shall be only as set forth in any separate license between you and
# BlackBerry Limited.
copy_partition() {
result=$(md5sum $1 $2)
if [ $? -ne 0 ]; then
log -t recovery "Error in getting md5sum for $1 and $2"
return 1
fi
# The result is in the format "<md5sum> <path>". We only need the md5sum portion.
set -A md5_sums ${result}
src_md5=${md5_sums[0]}
target_md5=${md5_sums[2]}
if [ "${src_md5}" != "${target_md5}" ]; then
log -t recovery "Installing $2 ..."
dd if=$1 of=$2 bs=${BLOCK_SIZE}
if [ $? -ne 0 ]; then
log -t recovery "Installing $2: failed"
return 1
else
log -t recovery "Installing $2: succeeded"
fi
else
log -t recovery "$2 already installed"
fi
return 0
}
get_md5sum() {
md5sum_result=$(dd if=$1 bs=${BLOCK_SIZE} count=$2 | md5sum)
if [ $? -ne 0 ]; then
log -t recovery "Error in getting md5sum for $1"
return 1
fi
# The result is in the format "<md5sum> <path>". We only need the md5sum portion.
set -A md5_sums ${md5sum_result}
echo ${md5_sums[0]}
}
copy_partition_blocks() {
src_md5=$(get_md5sum $1 $3)
target_md5=$(get_md5sum $2 $3)
if [ "${src_md5}" != "${target_md5}" ]; then
log -t recovery "Installing $2 ..."
dd if=$1 of=$2 bs=${BLOCK_SIZE} count=$3
if [ $? -ne 0 ]; then
log -t recovery "Installing $2: failed"
return 1
else
log -t recovery "Installing $2: succeeded"
fi
else
log -t recovery "$2 already installed"
fi
return 0
}
PATH_ROOT=/dev/block/bootdevice/by-name
BOOT_PATH=${PATH_ROOT}/boot
BOOT_SIG_PATH=${PATH_ROOT}/bootsig
RECOVERY_PATH=${PATH_ROOT}/recovery
RECOVERY_SIG_PATH=${PATH_ROOT}/recoverysig
# For Athena, the boot partition is 65536KB and recovery partition is 65532KB
# We can only copy 65532KB from boot to recovery, i.e. 16383 blocks (block=4KB)
NUM_OF_BLOCKS="16383"
BLOCK_SIZE="4096"
copy_partition_blocks ${BOOT_PATH} ${RECOVERY_PATH} ${NUM_OF_BLOCKS}
copy_partition ${BOOT_SIG_PATH} ${RECOVERY_SIG_PATH}
|