blob: 5b07d5d612e9643ce99a43d86adaffcd63aeddb6 [file] [log] [blame]
Tristan Muntsingerbcdc07b2019-10-16 22:56:19 -07001#!/bin/bash
2
3# Copyright 2019 Google Inc. All rights reserved.
4
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8
9# http://www.apache.org/licenses/LICENSE-2.0
10
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17source "${ANDROID_BUILD_TOP}/external/shflags/src/shflags"
18
19DEFINE_string loader1 \
20 "" "Path to loader1 image (partition 1)" "l"
21DEFINE_string env \
22 "" "Path to env image (partition 2)" "e"
23DEFINE_string loader2 \
24 "" "Path to loader2 image (partition 3)" "u"
25DEFINE_string trust \
26 "" "Path to trust image (partition 4)" "t"
27DEFINE_string rootfs \
28 "" "Path to rootfs image (partition 5)" "r"
29DEFINE_string tftp \
30 "192.168.0.1" "TFTP server address" "f"
31DEFINE_string tftpdir \
32 "/tftpboot" "TFTP server directory" "d"
Tristan Muntsinger71eaf9e2019-11-08 19:02:36 -080033DEFINE_string version \
Tristan Muntsingera601d6a2019-11-08 19:06:29 -080034 "2" "Specify which manifest version to use (default: latest)" "v"
35DEFINE_string ethaddr \
36 "" "MAC address of device to DFU (default: all)" "m"
Tristan Muntsingerbcdc07b2019-10-16 22:56:19 -070037
38FLAGS_HELP="USAGE: $0 [flags]"
39
40FLAGS "$@" || exit $?
41eval set -- "${FLAGS_ARGV}"
42
43for arg in "$@" ; do
44 flags_help
45 exit 1
46done
47
48confirm() {
49 read -r -p "${1:-Are you sure you want to continue? [y/N]} " response
50 case "$response" in
51 [yY][eE][sS]|[yY])
52 true
53 ;;
54 *)
55 false
56 ;;
57 esac
58}
59
60createManifest() {
Tristan Muntsinger71eaf9e2019-11-08 19:02:36 -080061 >>manifest.txt
Tristan Muntsingerbcdc07b2019-10-16 22:56:19 -070062}
63
Tristan Muntsinger08e13d02019-10-30 17:06:18 -070064addKVToManifest() {
65 key=$1
66 value=$2
67 grep -q "^${key}=" manifest.txt && \
68 sed -i "s/^${key}=.*/${key}=${value}/" manifest.txt || \
69 echo "${key}=${value}" >> manifest.txt
70}
71
Tristan Muntsinger9b8c88f2019-11-19 17:23:37 -080072addShaToManifest() {
73 key="Sha"
Tristan Muntsingerbcdc07b2019-10-16 22:56:19 -070074 cd "${ANDROID_BUILD_TOP}/device/google/cuttlefish_common"
Tristan Muntsinger9b8c88f2019-11-19 17:23:37 -080075 Sha=`git rev-parse HEAD`
Tristan Muntsingerbcdc07b2019-10-16 22:56:19 -070076 cd -
77 cd "${ANDROID_BUILD_TOP}/external/u-boot"
Tristan Muntsinger9b8c88f2019-11-19 17:23:37 -080078 Sha="$Sha,`git rev-parse HEAD`"
Tristan Muntsingerbcdc07b2019-10-16 22:56:19 -070079 cd -
80 cd "${ANDROID_BUILD_TOP}/external/arm-trusted-firmware"
Tristan Muntsinger9b8c88f2019-11-19 17:23:37 -080081 Sha="$Sha,`git rev-parse HEAD`"
Tristan Muntsingerbcdc07b2019-10-16 22:56:19 -070082 cd -
Tristan Muntsinger08e13d02019-10-30 17:06:18 -070083
Tristan Muntsinger9b8c88f2019-11-19 17:23:37 -080084 addKVToManifest "${key}" "${Sha}"
Tristan Muntsingerbcdc07b2019-10-16 22:56:19 -070085}
86
Tristan Muntsinger08e13d02019-10-30 17:06:18 -070087addPathToManifest() {
Tristan Muntsingerbcdc07b2019-10-16 22:56:19 -070088 key=$1
89 path=$2
90
91 if [ "${path}" != "" ]; then
92 filename=$(basename $path)
Tristan Muntsinger2f512692019-10-30 16:30:56 -070093 filetype=`file -b --mime-type "${path}"`
94 if [ "$key" == "UbootEnv" ] && [ "${filetype}" == "application/gzip" ]; then
Tristan Muntsingerbcdc07b2019-10-16 22:56:19 -070095 echo "error: gzip not supported for env images"
96 fi
Tristan Muntsinger2f512692019-10-30 16:30:56 -070097 if [ "$key" != "UbootEnv" ] && [ "${filetype}" != "application/gzip" ]; then
Tristan Muntsingerbcdc07b2019-10-16 22:56:19 -070098 echo "warning: gzip recommended for all non-env images"
99 confirm || exit 1
100 fi
Tristan Muntsinger2f512692019-10-30 16:30:56 -0700101 if [ ! "${path}" -ef "${FLAGS_tftpdir}/${filename}" ]; then
102 cp "${path}" "${FLAGS_tftpdir}/"
Tristan Muntsingerbcdc07b2019-10-16 22:56:19 -0700103 fi
104 else
105 unset filename
106 fi
Tristan Muntsinger08e13d02019-10-30 17:06:18 -0700107
108 addKVToManifest "${key}" "${filename}"
Tristan Muntsingerbcdc07b2019-10-16 22:56:19 -0700109}
110
111createManifest
Tristan Muntsinger71eaf9e2019-11-08 19:02:36 -0800112addKVToManifest ManifestVersion ${FLAGS_version}
Tristan Muntsinger08e13d02019-10-30 17:06:18 -0700113addKVToManifest TftpServer ${FLAGS_tftp}
Tristan Muntsingera601d6a2019-11-08 19:06:29 -0800114addKVToManifest DFUethaddr ${FLAGS_ethaddr}
Tristan Muntsinger08e13d02019-10-30 17:06:18 -0700115addPathToManifest RootfsImg ${FLAGS_rootfs}
116addPathToManifest UbootEnv ${FLAGS_env}
117addPathToManifest TplSplImg ${FLAGS_loader1}
118addPathToManifest UbootItb ${FLAGS_loader2}
Tristan Muntsinger9b8c88f2019-11-19 17:23:37 -0800119addShaToManifest