Tristan Muntsinger | bcdc07b | 2019-10-16 22:56:19 -0700 | [diff] [blame] | 1 | #!/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 | |
| 17 | source "${ANDROID_BUILD_TOP}/external/shflags/src/shflags" |
| 18 | |
| 19 | DEFINE_string loader1 \ |
| 20 | "" "Path to loader1 image (partition 1)" "l" |
| 21 | DEFINE_string env \ |
| 22 | "" "Path to env image (partition 2)" "e" |
| 23 | DEFINE_string loader2 \ |
| 24 | "" "Path to loader2 image (partition 3)" "u" |
| 25 | DEFINE_string trust \ |
| 26 | "" "Path to trust image (partition 4)" "t" |
| 27 | DEFINE_string rootfs \ |
| 28 | "" "Path to rootfs image (partition 5)" "r" |
| 29 | DEFINE_string tftp \ |
| 30 | "192.168.0.1" "TFTP server address" "f" |
| 31 | DEFINE_string tftpdir \ |
| 32 | "/tftpboot" "TFTP server directory" "d" |
Tristan Muntsinger | 71eaf9e | 2019-11-08 19:02:36 -0800 | [diff] [blame] | 33 | DEFINE_string version \ |
Tristan Muntsinger | a601d6a | 2019-11-08 19:06:29 -0800 | [diff] [blame] | 34 | "2" "Specify which manifest version to use (default: latest)" "v" |
| 35 | DEFINE_string ethaddr \ |
| 36 | "" "MAC address of device to DFU (default: all)" "m" |
Tristan Muntsinger | bcdc07b | 2019-10-16 22:56:19 -0700 | [diff] [blame] | 37 | |
| 38 | FLAGS_HELP="USAGE: $0 [flags]" |
| 39 | |
| 40 | FLAGS "$@" || exit $? |
| 41 | eval set -- "${FLAGS_ARGV}" |
| 42 | |
| 43 | for arg in "$@" ; do |
| 44 | flags_help |
| 45 | exit 1 |
| 46 | done |
| 47 | |
| 48 | confirm() { |
| 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 | |
| 60 | createManifest() { |
Tristan Muntsinger | 71eaf9e | 2019-11-08 19:02:36 -0800 | [diff] [blame] | 61 | >>manifest.txt |
Tristan Muntsinger | bcdc07b | 2019-10-16 22:56:19 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Tristan Muntsinger | 08e13d0 | 2019-10-30 17:06:18 -0700 | [diff] [blame] | 64 | addKVToManifest() { |
| 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 Muntsinger | 9b8c88f | 2019-11-19 17:23:37 -0800 | [diff] [blame] | 72 | addShaToManifest() { |
| 73 | key="Sha" |
Tristan Muntsinger | bcdc07b | 2019-10-16 22:56:19 -0700 | [diff] [blame] | 74 | cd "${ANDROID_BUILD_TOP}/device/google/cuttlefish_common" |
Tristan Muntsinger | 9b8c88f | 2019-11-19 17:23:37 -0800 | [diff] [blame] | 75 | Sha=`git rev-parse HEAD` |
Tristan Muntsinger | bcdc07b | 2019-10-16 22:56:19 -0700 | [diff] [blame] | 76 | cd - |
| 77 | cd "${ANDROID_BUILD_TOP}/external/u-boot" |
Tristan Muntsinger | 9b8c88f | 2019-11-19 17:23:37 -0800 | [diff] [blame] | 78 | Sha="$Sha,`git rev-parse HEAD`" |
Tristan Muntsinger | bcdc07b | 2019-10-16 22:56:19 -0700 | [diff] [blame] | 79 | cd - |
| 80 | cd "${ANDROID_BUILD_TOP}/external/arm-trusted-firmware" |
Tristan Muntsinger | 9b8c88f | 2019-11-19 17:23:37 -0800 | [diff] [blame] | 81 | Sha="$Sha,`git rev-parse HEAD`" |
Tristan Muntsinger | bcdc07b | 2019-10-16 22:56:19 -0700 | [diff] [blame] | 82 | cd - |
Tristan Muntsinger | 08e13d0 | 2019-10-30 17:06:18 -0700 | [diff] [blame] | 83 | |
Tristan Muntsinger | 9b8c88f | 2019-11-19 17:23:37 -0800 | [diff] [blame] | 84 | addKVToManifest "${key}" "${Sha}" |
Tristan Muntsinger | bcdc07b | 2019-10-16 22:56:19 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Tristan Muntsinger | 08e13d0 | 2019-10-30 17:06:18 -0700 | [diff] [blame] | 87 | addPathToManifest() { |
Tristan Muntsinger | bcdc07b | 2019-10-16 22:56:19 -0700 | [diff] [blame] | 88 | key=$1 |
| 89 | path=$2 |
| 90 | |
| 91 | if [ "${path}" != "" ]; then |
| 92 | filename=$(basename $path) |
Tristan Muntsinger | 2f51269 | 2019-10-30 16:30:56 -0700 | [diff] [blame] | 93 | filetype=`file -b --mime-type "${path}"` |
| 94 | if [ "$key" == "UbootEnv" ] && [ "${filetype}" == "application/gzip" ]; then |
Tristan Muntsinger | bcdc07b | 2019-10-16 22:56:19 -0700 | [diff] [blame] | 95 | echo "error: gzip not supported for env images" |
| 96 | fi |
Tristan Muntsinger | 2f51269 | 2019-10-30 16:30:56 -0700 | [diff] [blame] | 97 | if [ "$key" != "UbootEnv" ] && [ "${filetype}" != "application/gzip" ]; then |
Tristan Muntsinger | bcdc07b | 2019-10-16 22:56:19 -0700 | [diff] [blame] | 98 | echo "warning: gzip recommended for all non-env images" |
| 99 | confirm || exit 1 |
| 100 | fi |
Tristan Muntsinger | 2f51269 | 2019-10-30 16:30:56 -0700 | [diff] [blame] | 101 | if [ ! "${path}" -ef "${FLAGS_tftpdir}/${filename}" ]; then |
| 102 | cp "${path}" "${FLAGS_tftpdir}/" |
Tristan Muntsinger | bcdc07b | 2019-10-16 22:56:19 -0700 | [diff] [blame] | 103 | fi |
| 104 | else |
| 105 | unset filename |
| 106 | fi |
Tristan Muntsinger | 08e13d0 | 2019-10-30 17:06:18 -0700 | [diff] [blame] | 107 | |
| 108 | addKVToManifest "${key}" "${filename}" |
Tristan Muntsinger | bcdc07b | 2019-10-16 22:56:19 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | createManifest |
Tristan Muntsinger | 71eaf9e | 2019-11-08 19:02:36 -0800 | [diff] [blame] | 112 | addKVToManifest ManifestVersion ${FLAGS_version} |
Tristan Muntsinger | 08e13d0 | 2019-10-30 17:06:18 -0700 | [diff] [blame] | 113 | addKVToManifest TftpServer ${FLAGS_tftp} |
Tristan Muntsinger | a601d6a | 2019-11-08 19:06:29 -0800 | [diff] [blame] | 114 | addKVToManifest DFUethaddr ${FLAGS_ethaddr} |
Tristan Muntsinger | 08e13d0 | 2019-10-30 17:06:18 -0700 | [diff] [blame] | 115 | addPathToManifest RootfsImg ${FLAGS_rootfs} |
| 116 | addPathToManifest UbootEnv ${FLAGS_env} |
| 117 | addPathToManifest TplSplImg ${FLAGS_loader1} |
| 118 | addPathToManifest UbootItb ${FLAGS_loader2} |
Tristan Muntsinger | 9b8c88f | 2019-11-19 17:23:37 -0800 | [diff] [blame] | 119 | addShaToManifest |