-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease_android.sh
More file actions
executable file
·174 lines (147 loc) · 5.77 KB
/
Copy pathrelease_android.sh
File metadata and controls
executable file
·174 lines (147 loc) · 5.77 KB
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
#!/bin/bash
set -e
set -u
set -o pipefail
SRC=$(dirname "$(readlink -e "$0")")
source "${SRC}/build_all.sh"
source "${SRC}/commit-binaries.sh"
# SpacemiT K1 projects in this repo tree
PROJECTS_AIOT=("pi-opensbi" "pi-u-boot" "build-bootloaders")
PROJECTS_REMOTES="spacemit github"
function add_commit_msg {
local -n commits_msg_ref="$1"
local title_prefix="$2"
local android_out="$3"
local toplevel=""
local commits_msg_value=""
pushd "${android_out}"
toplevel=$(git rev-parse --sq --show-toplevel)
if [[ -v "commits_msg_ref[${toplevel}]" ]]; then
commits_msg_value="${commits_msg_ref[${toplevel}]}"
if ! [[ ${commits_msg_value} =~ ${title_prefix} ]]; then
unset commits_msg_ref["${toplevel}"]
commits_msg_ref+=(["${toplevel}"]="${commits_msg_value}/${title_prefix}")
fi
else
commits_msg_ref+=(["${toplevel}"]="${title_prefix}")
fi
popd
}
function copy_binaries {
local out="$1"
local android_out="$2"
local mode="$3"
# OpenSBI firmware
[ -f "${out}/fw_dynamic-${mode}.bin" ] && cp "${out}/fw_dynamic-${mode}.bin" "${android_out}/"
[ -f "${out}/fw_dynamic.itb" ] && cp -f "${out}/fw_dynamic.itb" "${android_out}/"
# U-Boot
if [ -f "${out}/u-boot-${mode}.itb" ]; then
cp "${out}/u-boot-${mode}.itb" "${android_out}/"
elif [ -f "${out}/u-boot-${mode}.bin" ]; then
cp "${out}/u-boot-${mode}.bin" "${android_out}/"
fi
[ -f "${out}/u-boot-spl-${mode}.bin" ] && cp "${out}/u-boot-spl-${mode}.bin" "${android_out}/"
[ -f "${out}/u-boot-${mode}.dtb" ] && cp "${out}/u-boot-${mode}.dtb" "${android_out}/"
[ -f "${out}/env-${mode}.bin" ] && cp "${out}/env-${mode}.bin" "${android_out}/"
# Flash-ready files (factory blobs, partition layout)
if [ -d "${out}/factory" ]; then
mkdir -p "${android_out}/factory"
cp -f "${out}/factory"/* "${android_out}/factory/"
fi
[ -f "${out}/partition_android.json" ] && cp -f "${out}/partition_android.json" "${android_out}/"
[ -f "${out}/partition_nor.json" ] && cp -f "${out}/partition_nor.json" "${android_out}/"
}
function usage {
cat <<DELIM__
usage: $(basename "$0") [options]
$ $(basename "$0") --aosp=<path-to-android-root>
Options:
--aosp Android Root path (required)
--commit (OPTIONAL) commit binaries in AOSP
--config (OPTIONAL) release ONLY for this board config file
(default: config/boards/spacemit-k1.yaml)
--help (OPTIONAL) display usage
--mode (OPTIONAL) [release|debug|factory] build only one mode
--no-build (OPTIONAL) don't rebuild the images
--silent (OPTIONAL) silent build commands
DELIM__
}
function main {
local aosp=""
local commit=false
local config=""
local build=true
local silent=false
local mode_list=(debug release)
local opts_args="aosp:,commit,config:,help,mode:,no-build,silent"
local opts=$(getopt -o '' -l "${opts_args}" -- "$@")
eval set -- "${opts}"
while true; do
case "$1" in
--aosp) aosp=$(find_path "$2"); shift 2 ;;
--commit) commit=true; shift ;;
--config)
config=$(find_path "$2")
[ -z "${config}" ] && error_usage_exit "Cannot find board config file"
shift 2 ;;
--help) usage; exit 0 ;;
--mode) mode_list=("$2"); shift 2 ;;
--silent) silent=true; shift ;;
--no-build) build=false; shift ;;
--) shift; break ;;
esac
done
# check arguments
[ -z "${aosp}" ] && error_usage_exit "Cannot find Android Root Path"
# set configs list
declare -a configs
if [ -n "${config}" ]; then
configs=("${config}")
else
configs=("${SRC}"/config/boards/*.yaml)
fi
# build configs
local binaries_path=""
local out_dir=""
declare -A commits_msg
check_env
pushd "${SRC}"
for board_config in "${configs[@]}"; do
binaries_path=$(config_value "${board_config}" android.binaries_path)
for mode in "${mode_list[@]}"; do
out_dir=$(out_dir "${board_config}" "${mode}")
if [[ "${build}" == true ]]; then
if [[ "${silent}" == true ]]; then
display_current_build "${board_config}" "all" "${mode}"
build_all "${board_config}" "true" "${mode}" &> /dev/null
else
build_all "${board_config}" "true" "${mode}"
fi
fi
! [ -d "${aosp}/${binaries_path}" ] && mkdir -p "${aosp}/${binaries_path}"
copy_binaries "${out_dir}" "${aosp}/${binaries_path}" "${mode}"
done
commit_title_prefix=$(board_name ${board_config})
add_commit_msg commits_msg "${commit_title_prefix}" "${aosp}/${binaries_path}"
done
popd
for abspath in "${!commits_msg[@]}"; do
commit_title_prefix="${commits_msg[${abspath}]}"
# we need the project name for commit_binaries(), not the
# full filepath
to_project=${abspath#${aosp}/}
if [ "${commit}" == true ]; then
commit_binaries --from-repo="${ROOT}" --from-projects="${PROJECTS_AIOT[*]}" \
--from-remotes="${PROJECTS_REMOTES}" \
--to-repo="${aosp}" --to-project="${to_project}" \
--title-prefix="${commit_title_prefix}"
else
commit_binaries --from-repo="${ROOT}" --from-projects="${PROJECTS_AIOT[*]}" \
--from-remotes="${PROJECTS_REMOTES}" \
--to-repo="${aosp}" --to-project="${to_project}" \
--title-prefix="${commit_title_prefix}" \
--dry-run
fi
done
}
main "$@"