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 | faaf1b3 | 2019-11-25 17:16:20 -0800 | [diff] [blame] | 37 | DEFINE_string kernel \ |
| 38 | "" "Path to kernel build dir" "k" |
Tristan Muntsinger | bcdc07b | 2019-10-16 22:56:19 -0700 | [diff] [blame] | 39 | |
Tristan Muntsinger | faaf1b3 | 2019-11-25 17:16:20 -0800 | [diff] [blame] | 40 | FLAGS_HELP="USAGE: $0 --kernel <dir> [flags]" |
Tristan Muntsinger | bcdc07b | 2019-10-16 22:56:19 -0700 | [diff] [blame] | 41 | |
| 42 | FLAGS "$@" || exit $? |
| 43 | eval set -- "${FLAGS_ARGV}" |
| 44 | |
| 45 | for arg in "$@" ; do |
| 46 | flags_help |
| 47 | exit 1 |
| 48 | done |
| 49 | |
Tristan Muntsinger | faaf1b3 | 2019-11-25 17:16:20 -0800 | [diff] [blame] | 50 | if [ -z ${FLAGS_kernel} ]; then |
| 51 | flags_help |
| 52 | exit 1 |
| 53 | fi |
| 54 | |
Tristan Muntsinger | bcdc07b | 2019-10-16 22:56:19 -0700 | [diff] [blame] | 55 | confirm() { |
| 56 | read -r -p "${1:-Are you sure you want to continue? [y/N]} " response |
| 57 | case "$response" in |
| 58 | [yY][eE][sS]|[yY]) |
| 59 | true |
| 60 | ;; |
| 61 | *) |
| 62 | false |
| 63 | ;; |
| 64 | esac |
| 65 | } |
| 66 | |
| 67 | createManifest() { |
Tristan Muntsinger | 71eaf9e | 2019-11-08 19:02:36 -0800 | [diff] [blame] | 68 | >>manifest.txt |
Tristan Muntsinger | bcdc07b | 2019-10-16 22:56:19 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Tristan Muntsinger | 08e13d0 | 2019-10-30 17:06:18 -0700 | [diff] [blame] | 71 | addKVToManifest() { |
| 72 | key=$1 |
| 73 | value=$2 |
| 74 | grep -q "^${key}=" manifest.txt && \ |
| 75 | sed -i "s/^${key}=.*/${key}=${value}/" manifest.txt || \ |
| 76 | echo "${key}=${value}" >> manifest.txt |
| 77 | } |
| 78 | |
Tristan Muntsinger | 9b8c88f | 2019-11-19 17:23:37 -0800 | [diff] [blame] | 79 | addShaToManifest() { |
Tristan Muntsinger | ca4e099 | 2019-11-26 17:24:24 -0800 | [diff] [blame] | 80 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" |
| 81 | addKVToManifest "Sha" `${DIR}/gen_sha.sh --kernel ${FLAGS_kernel}` |
Tristan Muntsinger | bcdc07b | 2019-10-16 22:56:19 -0700 | [diff] [blame] | 82 | } |
| 83 | |
Tristan Muntsinger | 08e13d0 | 2019-10-30 17:06:18 -0700 | [diff] [blame] | 84 | addPathToManifest() { |
Tristan Muntsinger | bcdc07b | 2019-10-16 22:56:19 -0700 | [diff] [blame] | 85 | key=$1 |
| 86 | path=$2 |
| 87 | |
| 88 | if [ "${path}" != "" ]; then |
| 89 | filename=$(basename $path) |
Tristan Muntsinger | 2f51269 | 2019-10-30 16:30:56 -0700 | [diff] [blame] | 90 | filetype=`file -b --mime-type "${path}"` |
| 91 | if [ "$key" == "UbootEnv" ] && [ "${filetype}" == "application/gzip" ]; then |
Tristan Muntsinger | bcdc07b | 2019-10-16 22:56:19 -0700 | [diff] [blame] | 92 | echo "error: gzip not supported for env images" |
| 93 | fi |
Tristan Muntsinger | 2f51269 | 2019-10-30 16:30:56 -0700 | [diff] [blame] | 94 | if [ "$key" != "UbootEnv" ] && [ "${filetype}" != "application/gzip" ]; then |
Tristan Muntsinger | bcdc07b | 2019-10-16 22:56:19 -0700 | [diff] [blame] | 95 | echo "warning: gzip recommended for all non-env images" |
| 96 | confirm || exit 1 |
| 97 | fi |
Tristan Muntsinger | 2f51269 | 2019-10-30 16:30:56 -0700 | [diff] [blame] | 98 | if [ ! "${path}" -ef "${FLAGS_tftpdir}/${filename}" ]; then |
| 99 | cp "${path}" "${FLAGS_tftpdir}/" |
Tristan Muntsinger | bcdc07b | 2019-10-16 22:56:19 -0700 | [diff] [blame] | 100 | fi |
| 101 | else |
| 102 | unset filename |
| 103 | fi |
Tristan Muntsinger | 08e13d0 | 2019-10-30 17:06:18 -0700 | [diff] [blame] | 104 | |
| 105 | addKVToManifest "${key}" "${filename}" |
Tristan Muntsinger | bcdc07b | 2019-10-16 22:56:19 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | createManifest |
Tristan Muntsinger | 71eaf9e | 2019-11-08 19:02:36 -0800 | [diff] [blame] | 109 | addKVToManifest ManifestVersion ${FLAGS_version} |
Tristan Muntsinger | 08e13d0 | 2019-10-30 17:06:18 -0700 | [diff] [blame] | 110 | addKVToManifest TftpServer ${FLAGS_tftp} |
Tristan Muntsinger | a601d6a | 2019-11-08 19:06:29 -0800 | [diff] [blame] | 111 | addKVToManifest DFUethaddr ${FLAGS_ethaddr} |
Tristan Muntsinger | 08e13d0 | 2019-10-30 17:06:18 -0700 | [diff] [blame] | 112 | addPathToManifest RootfsImg ${FLAGS_rootfs} |
| 113 | addPathToManifest UbootEnv ${FLAGS_env} |
| 114 | addPathToManifest TplSplImg ${FLAGS_loader1} |
| 115 | addPathToManifest UbootItb ${FLAGS_loader2} |
Tristan Muntsinger | 9b8c88f | 2019-11-19 17:23:37 -0800 | [diff] [blame] | 116 | addShaToManifest |