| Gunnar Mills | 6b5b27e | 2017-03-01 21:37:01 -0600 | [diff] [blame] | 1 | #!/bin/bash | 
| Gunnar Mills | f8f1130 | 2017-03-08 13:11:33 -0600 | [diff] [blame] | 2 | set -eo pipefail | 
| Gunnar Mills | e822190 | 2017-02-03 15:59:06 -0600 | [diff] [blame] | 3 |  | 
| Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 4 | help=$'Generate Tarball with PNOR image and MANIFEST Script | 
| Gunnar Mills | e822190 | 2017-02-03 15:59:06 -0600 | [diff] [blame] | 5 |  | 
| Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 6 | Generates a PNOR SquashFS image from the PNOR image for VPNOR, | 
|  | 7 | Or use a static layout raw PNOR image, | 
| Gunnar Mills | 2941435 | 2017-10-25 11:07:43 -0500 | [diff] [blame] | 8 | Creates a MANIFEST for image verification and recreation | 
| Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 9 | Packages the image and MANIFEST together in a tarball | 
| Gunnar Mills | e822190 | 2017-02-03 15:59:06 -0600 | [diff] [blame] | 10 |  | 
| Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 11 | usage: generate-tar [OPTION] <PNOR FILE>... | 
| Gunnar Mills | e822190 | 2017-02-03 15:59:06 -0600 | [diff] [blame] | 12 |  | 
|  | 13 | Options: | 
| Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 14 | -i, --image <squashfs|static> | 
|  | 15 | Generate SquashFS image or use static PNOR | 
| Gunnar Mills | 37751f9 | 2017-02-07 21:05:01 -0600 | [diff] [blame] | 16 | -f, --file <file>      Specify destination file. Defaults to | 
| Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 17 | `pwd`/<PNOR FILE>.pnor.<image_type>.tar[.gz] if | 
|  | 18 | unspecified. | 
|  | 19 | (For example, | 
|  | 20 | * "generate-tar -i squashfs my.pnor" would generate | 
|  | 21 | `pwd`/my.pnor.squashfs.tar | 
|  | 22 | * "generate-tar -i static my.pnor" would generate | 
|  | 23 | `pwd`/my.pnor.static.tar.gz) | 
| Eddie James | 643e730 | 2018-02-26 15:23:43 -0600 | [diff] [blame] | 24 | -s, --sign <path>      Sign the image. The optional path argument specifies | 
|  | 25 | the private key file. Defaults to the bash variable | 
|  | 26 | PRIVATE_KEY_PATH if available, or else uses the | 
|  | 27 | open-source private key in this script. | 
| Lei YU | 647d613 | 2019-12-31 14:35:00 +0800 | [diff] [blame] | 28 | -m, --machine <name>   Optionally specify the target machine name of this | 
|  | 29 | image. | 
| Gunnar Mills | e822190 | 2017-02-03 15:59:06 -0600 | [diff] [blame] | 30 | -h, --help             Display this help text and exit. | 
|  | 31 | ' | 
| Eddie James | 643e730 | 2018-02-26 15:23:43 -0600 | [diff] [blame] | 32 |  | 
|  | 33 | private_key=$'-----BEGIN PRIVATE KEY----- | 
|  | 34 | MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAPvSDLu6slkP1gri | 
|  | 35 | PaeQXL9ysD69J/HjbBCIQ0RPfeWBb75US1tRTjPP0Ub8CtH8ExVf8iF1ulsZA78B | 
|  | 36 | zIjBYZVp9pyD6LbpZ/hjV7rIH6dTNhoVpdA+F8LzmQ7cyhHG8l2JMvdunwF2uX5k | 
|  | 37 | D4WDcZt/ITKZNQNavPtmIyD5HprdAgMBAAECgYEAuQkTSi5ZNpAoWz76xtGRFSwU | 
|  | 38 | zUT4wQi3Mz6tDtjKTYXasiQGa0dHC1M9F8fDu6BZ9W7W4Dc9hArRcdzEighuxoI/ | 
|  | 39 | nZI/0uL89iUEywnDEIHuS6D5JlZaj86/nx9YvQnO8F/seM+MX0EAWVrd5wC7aAF1 | 
|  | 40 | h6Fu7ykZB4ggUjQAWwECQQD+AUiDOEO+8btLJ135dQfSGc5VFcZiequnKWVm6uXt | 
|  | 41 | rX771hEYjYMjLqWGFg9G4gE3GuABM5chMINuQQUivy8tAkEA/cxfy19XkjtqcMgE | 
|  | 42 | x/UDt6Nr+Ky/tk+4Y65WxPRDas0uxFOPk/vEjgVmz1k/TAy9G4giisluTvtmltr5 | 
|  | 43 | DCLocQJBAJnRHx9PiD7uVhRJz6/L/iNuOzPtTsi+Loq5F83+O6T15qsM1CeBMsOw | 
|  | 44 | cM5FN5UeMcwz+yjfHAsePMkcmMaU7jUCQHlg9+N8upXuIo7Dqj2zOU7nMmkgvSNE | 
|  | 45 | 5yuNImRZabC3ZolwaTdd7nf5r1y1Eyec5Ag5yENV6JKPe1Xkbb1XKJECQDngA0h4 | 
|  | 46 | 6ATvfP1Vrx4CbP11eKXbCsZ9OGPHSgyvVjn68oY5ZP3uPsIattoN7dE2BRfuJm7m | 
|  | 47 | F0nIdUAhR0yTfKM= | 
|  | 48 | -----END PRIVATE KEY----- | 
|  | 49 | ' | 
|  | 50 |  | 
| Adriana Kobylak | 1e4a7f2 | 2017-07-09 16:12:36 -0500 | [diff] [blame] | 51 | # Reference the ffs structures at: | 
|  | 52 | # https://github.com/open-power/hostboot/blob/master/src/usr/pnor/common/ffs_hb.H | 
|  | 53 | # https://github.com/open-power/hostboot/blob/master/src/usr/pnor/ffs.h | 
| Gunnar Mills | d4908a4 | 2017-03-07 08:25:59 -0600 | [diff] [blame] | 54 | let ffs_entry_size=128 | 
| Adriana Kobylak | 1e4a7f2 | 2017-07-09 16:12:36 -0500 | [diff] [blame] | 55 | let vercheck_offset=112 | 
| Eddie James | 643e730 | 2018-02-26 15:23:43 -0600 | [diff] [blame] | 56 | do_sign=false | 
|  | 57 | private_key_path="${PRIVATE_KEY_PATH}" | 
| Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 58 | image_type="" | 
| Michael Tritz | 8f39673 | 2017-06-09 10:55:35 -0500 | [diff] [blame] | 59 | outfile="" | 
| Gunnar Mills | 6b5b27e | 2017-03-01 21:37:01 -0600 | [diff] [blame] | 60 | declare -a partitions=() | 
|  | 61 | tocfile="pnor.toc" | 
| Lei YU | 647d613 | 2019-12-31 14:35:00 +0800 | [diff] [blame] | 62 | machine_name="" | 
| Gunnar Mills | 37751f9 | 2017-02-07 21:05:01 -0600 | [diff] [blame] | 63 |  | 
| Gunnar Mills | e822190 | 2017-02-03 15:59:06 -0600 | [diff] [blame] | 64 | while [[ $# -gt 0 ]]; do | 
|  | 65 | key="$1" | 
|  | 66 | case $key in | 
| Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 67 | -i|--image) | 
|  | 68 | image_type="$2" | 
|  | 69 | shift 2 | 
|  | 70 | ;; | 
| Gunnar Mills | 37751f9 | 2017-02-07 21:05:01 -0600 | [diff] [blame] | 71 | -f|--file) | 
|  | 72 | outfile="$2" | 
|  | 73 | shift 2 | 
|  | 74 | ;; | 
| Eddie James | 643e730 | 2018-02-26 15:23:43 -0600 | [diff] [blame] | 75 | -s|--sign) | 
|  | 76 | do_sign=true | 
|  | 77 | if [[ ! -z "${2}"  && "${2}" != -* ]]; then | 
|  | 78 | private_key_path="$2" | 
|  | 79 | shift 2 | 
|  | 80 | else | 
|  | 81 | shift 1 | 
|  | 82 | fi | 
|  | 83 | ;; | 
| Lei YU | 647d613 | 2019-12-31 14:35:00 +0800 | [diff] [blame] | 84 | -m|--machine) | 
|  | 85 | machine_name="$2" | 
|  | 86 | shift 2 | 
|  | 87 | ;; | 
| Gunnar Mills | e822190 | 2017-02-03 15:59:06 -0600 | [diff] [blame] | 88 | -h|--help) | 
|  | 89 | echo "$help" | 
|  | 90 | exit | 
|  | 91 | ;; | 
|  | 92 | *) | 
| Gunnar Mills | c15b02d | 2017-03-03 10:28:37 -0600 | [diff] [blame] | 93 | pnorfile="$1" | 
|  | 94 | shift 1 | 
| Gunnar Mills | e822190 | 2017-02-03 15:59:06 -0600 | [diff] [blame] | 95 | ;; | 
|  | 96 | esac | 
|  | 97 | done | 
| Gunnar Mills | 18f7cdb | 2017-02-07 16:44:19 -0600 | [diff] [blame] | 98 |  | 
| Gunnar Mills | c15b02d | 2017-03-03 10:28:37 -0600 | [diff] [blame] | 99 | if [ ! -f "${pnorfile}" ]; then | 
|  | 100 | echo "Please enter a valid PNOR file." | 
|  | 101 | echo "$help" | 
|  | 102 | exit 1 | 
|  | 103 | fi | 
|  | 104 |  | 
| Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 105 | if [[ "${image_type}" == "squashfs" ]]; then | 
|  | 106 | echo "Will generate squashfs image for VPNOR" | 
|  | 107 | elif [[ "${image_type}" == "static" ]]; then | 
|  | 108 | echo "Will use static image for PNOR" | 
|  | 109 | else | 
|  | 110 | echo "Please specify the image type, \"squashfs\" or \"static\"" | 
|  | 111 | echo | 
|  | 112 | echo "$help" | 
|  | 113 | exit 1 | 
|  | 114 | fi | 
|  | 115 |  | 
| Michael Tritz | 8f39673 | 2017-06-09 10:55:35 -0500 | [diff] [blame] | 116 | if [[ -z $outfile ]]; then | 
|  | 117 | if [[ ${pnorfile##*.} == "pnor" ]]; then | 
| Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 118 | outfile=`pwd`/${pnorfile##*/}.$image_type.tar | 
| Michael Tritz | 8f39673 | 2017-06-09 10:55:35 -0500 | [diff] [blame] | 119 | else | 
| Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 120 | outfile=`pwd`/${pnorfile##*/}.pnor.$image_type.tar | 
|  | 121 | fi | 
|  | 122 | if [[ "${image_type}" == "static" ]]; then | 
|  | 123 | # Append .gz so the tarball is compressed | 
|  | 124 | outfile=$outfile.gz | 
| Michael Tritz | 8f39673 | 2017-06-09 10:55:35 -0500 | [diff] [blame] | 125 | fi | 
|  | 126 | else | 
|  | 127 | if [[ $outfile != /* ]]; then | 
|  | 128 | outfile=`pwd`/$outfile | 
|  | 129 | fi | 
|  | 130 | fi | 
|  | 131 |  | 
| Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 132 |  | 
| Gunnar Mills | f8f1130 | 2017-03-08 13:11:33 -0600 | [diff] [blame] | 133 | scratch_dir=`mktemp -d` | 
| Lei YU | 00d8ade | 2020-01-14 11:30:04 +0800 | [diff] [blame] | 134 | # Remove the temp directory on exit. | 
|  | 135 | # The files in the temp directory may contain read-only files, so add | 
|  | 136 | # --interactive=never to skip the prompt. | 
|  | 137 | trap "{ rm -r --interactive=never ${scratch_dir}; }" EXIT | 
| Gunnar Mills | 6b5b27e | 2017-03-01 21:37:01 -0600 | [diff] [blame] | 138 |  | 
| Eddie James | 643e730 | 2018-02-26 15:23:43 -0600 | [diff] [blame] | 139 | if [[ "${do_sign}" == true ]]; then | 
|  | 140 | if [[ -z "${private_key_path}" ]]; then | 
|  | 141 | private_key_path=${scratch_dir}/OpenBMC.priv | 
|  | 142 | echo "${private_key}" > "${private_key_path}" | 
|  | 143 | echo "Image is NOT secure!! Signing with the open private key!" | 
|  | 144 | else | 
|  | 145 | if [[ ! -f "${private_key_path}" ]]; then | 
|  | 146 | echo "Couldn't find private key ${private_key_path}." | 
|  | 147 | exit 1 | 
|  | 148 | fi | 
|  | 149 |  | 
|  | 150 | echo "Signing with ${private_key_path}." | 
|  | 151 | fi | 
|  | 152 |  | 
|  | 153 | public_key_file=publickey | 
|  | 154 | public_key_path=${scratch_dir}/$public_key_file | 
|  | 155 | openssl pkey -in "${private_key_path}" -pubout -out ${public_key_path} | 
|  | 156 | fi | 
|  | 157 |  | 
| Gunnar Mills | 6b5b27e | 2017-03-01 21:37:01 -0600 | [diff] [blame] | 158 | echo "Parsing PNOR TOC..." | 
| Gunnar Mills | d4908a4 | 2017-03-07 08:25:59 -0600 | [diff] [blame] | 159 |  | 
| Adriana Kobylak | 851bc06 | 2019-06-05 14:33:06 -0500 | [diff] [blame] | 160 | pnor_dir="${scratch_dir}/pnor" | 
|  | 161 | mkdir ${pnor_dir} | 
|  | 162 |  | 
|  | 163 | pflash --partition=part --read=${pnor_dir}/part -F ${pnorfile} | 
|  | 164 | pflash --partition=VERSION --read=${pnor_dir}/VERSION -F ${pnorfile} | 
| Oliver O'Halloran | d23b5b7 | 2019-07-30 17:46:11 +1000 | [diff] [blame] | 165 | version_size=$(wc -c ${pnor_dir}/VERSION | cut -d' ' -f 1) | 
| Adriana Kobylak | 851bc06 | 2019-06-05 14:33:06 -0500 | [diff] [blame] | 166 | magic_number=$(xxd -p -l 4 ${pnor_dir}/VERSION) | 
| Samuel Mendoza-Jonas | d1d1921 | 2018-06-01 14:02:24 +1000 | [diff] [blame] | 167 | # Check if VERSION is signed. A signed version partition will have an extra | 
|  | 168 | # 4K header starting with the magic number 0x17082011, see: | 
|  | 169 | # https://github.com/open-power/skiboot/blob/master/libstb/container.h#L47 | 
| Oliver O'Halloran | d23b5b7 | 2019-07-30 17:46:11 +1000 | [diff] [blame] | 170 | if [ "$version_size" == "8192" -a "$magic_number" == "17082011" ]; then | 
| Samuel Mendoza-Jonas | d1d1921 | 2018-06-01 14:02:24 +1000 | [diff] [blame] | 171 | # Advance past the STB header (4K, indexed from 1) | 
| Adriana Kobylak | 851bc06 | 2019-06-05 14:33:06 -0500 | [diff] [blame] | 172 | cp ${pnor_dir}/VERSION ${pnor_dir}/VERSION_FULL | 
|  | 173 | tail --bytes=+4097 ${pnor_dir}/VERSION_FULL > ${pnor_dir}/VERSION | 
| Samuel Mendoza-Jonas | d1d1921 | 2018-06-01 14:02:24 +1000 | [diff] [blame] | 174 | fi | 
| Gunnar Mills | 6b5b27e | 2017-03-01 21:37:01 -0600 | [diff] [blame] | 175 | { | 
| Adriana Kobylak | 851bc06 | 2019-06-05 14:33:06 -0500 | [diff] [blame] | 176 | version=$(head -n 1 ${pnor_dir}/VERSION) | 
| Gunnar Mills | 2f27b74 | 2017-03-20 13:46:30 -0500 | [diff] [blame] | 177 | echo "version=$version" | 
| Adriana Kobylak | 851bc06 | 2019-06-05 14:33:06 -0500 | [diff] [blame] | 178 | extended_version=$(echo $(tail -n +2 ${pnor_dir}/VERSION)|tr ' ' ',') | 
| Saqib Khan | 029b825 | 2017-03-22 21:38:07 -0500 | [diff] [blame] | 179 | echo "extended_version=$extended_version" | 
| Gunnar Mills | 6b5b27e | 2017-03-01 21:37:01 -0600 | [diff] [blame] | 180 | while read line; do | 
|  | 181 | if [[ $line == "ID="* ]]; then | 
| Gunnar Mills | e0ed302 | 2017-03-02 16:16:19 -0600 | [diff] [blame] | 182 | # This line looks like | 
|  | 183 | # "ID=05 MVPD 000d9000..00169000 (actual=00090000) [ECC]" | 
| Gunnar Mills | 6b5b27e | 2017-03-01 21:37:01 -0600 | [diff] [blame] | 184 | read -r -a fields <<< "$line" | 
| Gunnar Mills | e0ed302 | 2017-03-02 16:16:19 -0600 | [diff] [blame] | 185 |  | 
| Gunnar Mills | d4908a4 | 2017-03-07 08:25:59 -0600 | [diff] [blame] | 186 | id=${fields[0]##*=} | 
| Adriana Kobylak | 1e4a7f2 | 2017-07-09 16:12:36 -0500 | [diff] [blame] | 187 | offset=$((${ffs_entry_size} * 10#${id} + ${vercheck_offset})) | 
| Adriana Kobylak | 851bc06 | 2019-06-05 14:33:06 -0500 | [diff] [blame] | 188 | vercheck=$(xxd -p -l  0x1 -seek ${offset} ${pnor_dir}/part) | 
| Michael Tritz | 1bd65ac | 2017-05-07 17:40:14 -0500 | [diff] [blame] | 189 | export flags=$(pflash --detail=$((10#$id)) -F ${pnorfile} | grep "\[" | | 
|  | 190 | sed 's/....$//' | tr '\n' ',' | sed 's/.$//') | 
|  | 191 | if [[ $flags != "" ]]; then | 
|  | 192 | flags=,$flags | 
|  | 193 | fi | 
|  | 194 |  | 
|  | 195 | if [[ $(echo $flags | grep "READONLY") == "" && | 
|  | 196 | $(echo $flags | grep "PRESERVED") == "" ]]; then | 
|  | 197 | flags=$flags,READWRITE | 
| Gunnar Mills | d4908a4 | 2017-03-07 08:25:59 -0600 | [diff] [blame] | 198 | fi | 
|  | 199 |  | 
| Gunnar Mills | e0ed302 | 2017-03-02 16:16:19 -0600 | [diff] [blame] | 200 | # Need the partition ID, name, start location, end location, and flags | 
| Adriana Kobylak | 1e4a7f2 | 2017-07-09 16:12:36 -0500 | [diff] [blame] | 201 | echo  "partition${id}=${fields[1]},${fields[2]/../,},${vercheck}${flags}" | 
| Gunnar Mills | d4908a4 | 2017-03-07 08:25:59 -0600 | [diff] [blame] | 202 |  | 
| Gunnar Mills | 6b5b27e | 2017-03-01 21:37:01 -0600 | [diff] [blame] | 203 | # Save the partition name | 
|  | 204 | partitions+=(${fields[1]}) | 
|  | 205 | fi | 
| Adriana Kobylak | 1e4a7f2 | 2017-07-09 16:12:36 -0500 | [diff] [blame] | 206 | # Don't need the BACKUP_PART partition | 
|  | 207 | done < <(pflash --info -F ${pnorfile} | grep -v "BACKUP") | 
| Adriana Kobylak | 851bc06 | 2019-06-05 14:33:06 -0500 | [diff] [blame] | 208 | } > ${pnor_dir}/${tocfile} | 
| Gunnar Mills | 37751f9 | 2017-02-07 21:05:01 -0600 | [diff] [blame] | 209 |  | 
| Gunnar Mills | 18f7cdb | 2017-02-07 16:44:19 -0600 | [diff] [blame] | 210 | for partition in "${partitions[@]}"; do | 
|  | 211 | echo "Reading ${partition}..." | 
| Gunnar Mills | f8f1130 | 2017-03-08 13:11:33 -0600 | [diff] [blame] | 212 | pflash --partition=${partition} \ | 
| Adriana Kobylak | 851bc06 | 2019-06-05 14:33:06 -0500 | [diff] [blame] | 213 | --read=${pnor_dir}/${partition} \ | 
| Gunnar Mills | f8f1130 | 2017-03-08 13:11:33 -0600 | [diff] [blame] | 214 | -F ${pnorfile} | 
| Gunnar Mills | 18f7cdb | 2017-02-07 16:44:19 -0600 | [diff] [blame] | 215 | done | 
| Gunnar Mills | 37751f9 | 2017-02-07 21:05:01 -0600 | [diff] [blame] | 216 |  | 
| Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 217 | manifest_location="MANIFEST" | 
|  | 218 | files_to_sign="$manifest_location $public_key_file" | 
|  | 219 |  | 
|  | 220 | # Go to scratch_dir | 
|  | 221 |  | 
|  | 222 | if [[ "${image_type}" == "squashfs" ]]; then | 
|  | 223 | echo "Creating SquashFS image..." | 
| Adriana Kobylak | 851bc06 | 2019-06-05 14:33:06 -0500 | [diff] [blame] | 224 | # Prepare pnor file in ${pnor_dir} | 
|  | 225 | cd "${pnor_dir}" | 
| Adriana Kobylak | 85f2540 | 2019-10-09 13:56:59 -0500 | [diff] [blame] | 226 | # Set permissions of partition files to read only | 
|  | 227 | chmod 440 * | 
| Adriana Kobylak | ddf2b74 | 2019-09-11 10:31:09 -0500 | [diff] [blame] | 228 | mksquashfs ${tocfile} ${partitions[*]} ${scratch_dir}/pnor.xz.squashfs -all-root | 
| Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 229 | cd "${scratch_dir}" | 
| Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 230 | files_to_sign+=" pnor.xz.squashfs" | 
|  | 231 | else | 
|  | 232 | cp ${pnorfile} ${scratch_dir} | 
|  | 233 | cd "${scratch_dir}" | 
|  | 234 | files_to_sign+=" $(basename ${pnorfile})" | 
|  | 235 | fi | 
| Gunnar Mills | 37751f9 | 2017-02-07 21:05:01 -0600 | [diff] [blame] | 236 |  | 
| Saqib Khan | 93433f0 | 2017-03-23 22:24:27 -0500 | [diff] [blame] | 237 | echo "Creating MANIFEST for the image" | 
| Leonel Gonzalez | c14a3d2 | 2017-06-22 12:49:38 -0500 | [diff] [blame] | 238 | echo -e "purpose=xyz.openbmc_project.Software.Version.VersionPurpose.Host\nversion=$version\n\ | 
| Saqib Khan | 7254f0e | 2017-04-10 21:45:37 -0500 | [diff] [blame] | 239 | extended_version=$extended_version" >> $manifest_location | 
| Saqib Khan | 93433f0 | 2017-03-23 22:24:27 -0500 | [diff] [blame] | 240 |  | 
| Lei YU | 647d613 | 2019-12-31 14:35:00 +0800 | [diff] [blame] | 241 | if [[ ! -z "${machine_name}" ]]; then | 
|  | 242 | echo -e "MachineName=${machine_name}" >> $manifest_location | 
|  | 243 | fi | 
|  | 244 |  | 
| Eddie James | 643e730 | 2018-02-26 15:23:43 -0600 | [diff] [blame] | 245 | if [[ "${do_sign}" == true ]]; then | 
|  | 246 | private_key_name=$(basename "${private_key_path}") | 
|  | 247 | key_type="${private_key_name%.*}" | 
|  | 248 | echo KeyType="${key_type}" >> $manifest_location | 
|  | 249 | echo HashType="RSA-SHA256" >> $manifest_location | 
|  | 250 |  | 
| Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 251 | for file in $files_to_sign; do | 
| Eddie James | 643e730 | 2018-02-26 15:23:43 -0600 | [diff] [blame] | 252 | openssl dgst -sha256 -sign ${private_key_path} -out "${file}.sig" $file | 
|  | 253 | done | 
|  | 254 |  | 
| Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 255 | additional_files="*.sig" | 
| Eddie James | 643e730 | 2018-02-26 15:23:43 -0600 | [diff] [blame] | 256 | fi | 
|  | 257 |  | 
| Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 258 | if [[ "${image_type}" == "squashfs" ]]; then | 
|  | 259 | echo "Generating tarball to contain the SquashFS image and its MANIFEST" | 
|  | 260 | tar -cvf $outfile $files_to_sign $additional_files | 
|  | 261 | echo "SquashFSTarball at ${outfile}" | 
|  | 262 | else | 
|  | 263 | tar -czvf $outfile $files_to_sign $additional_files | 
|  | 264 | echo "Static layout tarball at $outfile" | 
|  | 265 | fi | 
| Saqib Khan | 93433f0 | 2017-03-23 22:24:27 -0500 | [diff] [blame] | 266 |  |