blob: c8b52960d21be76ef95fd1996c6456ec1794e4f3 [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 Muntsingerfaaf1b32019-11-25 17:16:20 -080037DEFINE_string kernel \
38 "" "Path to kernel build dir" "k"
Tristan Muntsingerbcdc07b2019-10-16 22:56:19 -070039
Tristan Muntsingerfaaf1b32019-11-25 17:16:20 -080040FLAGS_HELP="USAGE: $0 --kernel <dir> [flags]"
Tristan Muntsingerbcdc07b2019-10-16 22:56:19 -070041
42FLAGS "$@" || exit $?
43eval set -- "${FLAGS_ARGV}"
44
45for arg in "$@" ; do
46 flags_help
47 exit 1
48done
49
Tristan Muntsingerfaaf1b32019-11-25 17:16:20 -080050if [ -z ${FLAGS_kernel} ]; then
51 flags_help
52 exit 1
53fi
54
Tristan Muntsingerbcdc07b2019-10-16 22:56:19 -070055confirm() {
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
67createManifest() {
Tristan Muntsinger71eaf9e2019-11-08 19:02:36 -080068 >>manifest.txt
Tristan Muntsingerbcdc07b2019-10-16 22:56:19 -070069}
70
Tristan Muntsinger08e13d02019-10-30 17:06:18 -070071addKVToManifest() {
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 Muntsinger9b8c88f2019-11-19 17:23:37 -080079addShaToManifest() {
Tristan Muntsingerca4e0992019-11-26 17:24:24 -080080 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
81 addKVToManifest "Sha" `${DIR}/gen_sha.sh --kernel ${FLAGS_kernel}`
Tristan Muntsingerbcdc07b2019-10-16 22:56:19 -070082}
83
Tristan Muntsinger08e13d02019-10-30 17:06:18 -070084addPathToManifest() {
Tristan Muntsingerbcdc07b2019-10-16 22:56:19 -070085 key=$1
86 path=$2
87
88 if [ "${path}" != "" ]; then
89 filename=$(basename $path)
Tristan Muntsinger2f512692019-10-30 16:30:56 -070090 filetype=`file -b --mime-type "${path}"`
91 if [ "$key" == "UbootEnv" ] && [ "${filetype}" == "application/gzip" ]; then
Tristan Muntsingerbcdc07b2019-10-16 22:56:19 -070092 echo "error: gzip not supported for env images"
93 fi
Tristan Muntsinger2f512692019-10-30 16:30:56 -070094 if [ "$key" != "UbootEnv" ] && [ "${filetype}" != "application/gzip" ]; then
Tristan Muntsingerbcdc07b2019-10-16 22:56:19 -070095 echo "warning: gzip recommended for all non-env images"
96 confirm || exit 1
97 fi
Tristan Muntsinger2f512692019-10-30 16:30:56 -070098 if [ ! "${path}" -ef "${FLAGS_tftpdir}/${filename}" ]; then
99 cp "${path}" "${FLAGS_tftpdir}/"
Tristan Muntsingerbcdc07b2019-10-16 22:56:19 -0700100 fi
101 else
102 unset filename
103 fi
Tristan Muntsinger08e13d02019-10-30 17:06:18 -0700104
105 addKVToManifest "${key}" "${filename}"
Tristan Muntsingerbcdc07b2019-10-16 22:56:19 -0700106}
107
108createManifest
Tristan Muntsinger71eaf9e2019-11-08 19:02:36 -0800109addKVToManifest ManifestVersion ${FLAGS_version}
Tristan Muntsinger08e13d02019-10-30 17:06:18 -0700110addKVToManifest TftpServer ${FLAGS_tftp}
Tristan Muntsingera601d6a2019-11-08 19:06:29 -0800111addKVToManifest DFUethaddr ${FLAGS_ethaddr}
Tristan Muntsinger08e13d02019-10-30 17:06:18 -0700112addPathToManifest RootfsImg ${FLAGS_rootfs}
113addPathToManifest UbootEnv ${FLAGS_env}
114addPathToManifest TplSplImg ${FLAGS_loader1}
115addPathToManifest UbootItb ${FLAGS_loader2}
Tristan Muntsinger9b8c88f2019-11-19 17:23:37 -0800116addShaToManifest