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: |
Patrick Williams | 15513db | 2022-12-08 06:23:24 -0600 | [diff] [blame] | 14 | -i, --image <squashfs|static> |
| 15 | Generate SquashFS image or use static PNOR |
| 16 | -f, --file <file> Specify destination file. Defaults to |
| 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) |
| 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. |
| 28 | -m, --machine <name> Optionally specify the target machine name of this |
| 29 | image. |
| 30 | -h, --help Display this help text and exit. |
Gunnar Mills | e822190 | 2017-02-03 15:59:06 -0600 | [diff] [blame] | 31 | ' |
Eddie James | 643e730 | 2018-02-26 15:23:43 -0600 | [diff] [blame] | 32 | |
| 33 | private_key=$'-----BEGIN PRIVATE KEY----- |
Rashmica Gupta | cb3de14 | 2024-07-05 15:50:40 +1000 | [diff] [blame] | 34 | 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 |
| 83 | JbmuCRNy7YvALVTzyQsQ4yw87BoONt1L |
Eddie James | 643e730 | 2018-02-26 15:23:43 -0600 | [diff] [blame] | 84 | -----END PRIVATE KEY----- |
| 85 | ' |
| 86 | |
Adriana Kobylak | 1e4a7f2 | 2017-07-09 16:12:36 -0500 | [diff] [blame] | 87 | # Reference the ffs structures at: |
| 88 | # https://github.com/open-power/hostboot/blob/master/src/usr/pnor/common/ffs_hb.H |
| 89 | # https://github.com/open-power/hostboot/blob/master/src/usr/pnor/ffs.h |
Adriana Kobylak | 7bd45a3 | 2021-04-20 19:45:05 +0000 | [diff] [blame] | 90 | ffs_entry_size=128 |
| 91 | vercheck_offset=112 |
Eddie James | 643e730 | 2018-02-26 15:23:43 -0600 | [diff] [blame] | 92 | do_sign=false |
Adriana Kobylak | 7bd45a3 | 2021-04-20 19:45:05 +0000 | [diff] [blame] | 93 | PRIVATE_KEY_PATH=${PRIVATE_KEY_PATH:-} |
Eddie James | 643e730 | 2018-02-26 15:23:43 -0600 | [diff] [blame] | 94 | private_key_path="${PRIVATE_KEY_PATH}" |
Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 95 | image_type="" |
Michael Tritz | 8f39673 | 2017-06-09 10:55:35 -0500 | [diff] [blame] | 96 | outfile="" |
Gunnar Mills | 6b5b27e | 2017-03-01 21:37:01 -0600 | [diff] [blame] | 97 | declare -a partitions=() |
| 98 | tocfile="pnor.toc" |
Lei YU | 647d613 | 2019-12-31 14:35:00 +0800 | [diff] [blame] | 99 | machine_name="" |
Gunnar Mills | 37751f9 | 2017-02-07 21:05:01 -0600 | [diff] [blame] | 100 | |
Gunnar Mills | e822190 | 2017-02-03 15:59:06 -0600 | [diff] [blame] | 101 | while [[ $# -gt 0 ]]; do |
| 102 | key="$1" |
| 103 | case $key in |
Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 104 | -i|--image) |
| 105 | image_type="$2" |
| 106 | shift 2 |
| 107 | ;; |
Gunnar Mills | 37751f9 | 2017-02-07 21:05:01 -0600 | [diff] [blame] | 108 | -f|--file) |
| 109 | outfile="$2" |
| 110 | shift 2 |
| 111 | ;; |
Eddie James | 643e730 | 2018-02-26 15:23:43 -0600 | [diff] [blame] | 112 | -s|--sign) |
| 113 | do_sign=true |
Adriana Kobylak | 7bd45a3 | 2021-04-20 19:45:05 +0000 | [diff] [blame] | 114 | if [[ -n "${2}" && "${2}" != -* ]]; then |
Eddie James | 643e730 | 2018-02-26 15:23:43 -0600 | [diff] [blame] | 115 | private_key_path="$2" |
| 116 | shift 2 |
| 117 | else |
| 118 | shift 1 |
| 119 | fi |
| 120 | ;; |
Lei YU | 647d613 | 2019-12-31 14:35:00 +0800 | [diff] [blame] | 121 | -m|--machine) |
| 122 | machine_name="$2" |
| 123 | shift 2 |
| 124 | ;; |
Gunnar Mills | e822190 | 2017-02-03 15:59:06 -0600 | [diff] [blame] | 125 | -h|--help) |
| 126 | echo "$help" |
| 127 | exit |
| 128 | ;; |
| 129 | *) |
Gunnar Mills | c15b02d | 2017-03-03 10:28:37 -0600 | [diff] [blame] | 130 | pnorfile="$1" |
| 131 | shift 1 |
Gunnar Mills | e822190 | 2017-02-03 15:59:06 -0600 | [diff] [blame] | 132 | ;; |
| 133 | esac |
| 134 | done |
Gunnar Mills | 18f7cdb | 2017-02-07 16:44:19 -0600 | [diff] [blame] | 135 | |
Gunnar Mills | c15b02d | 2017-03-03 10:28:37 -0600 | [diff] [blame] | 136 | if [ ! -f "${pnorfile}" ]; then |
| 137 | echo "Please enter a valid PNOR file." |
| 138 | echo "$help" |
| 139 | exit 1 |
| 140 | fi |
| 141 | |
Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 142 | if [[ "${image_type}" == "squashfs" ]]; then |
| 143 | echo "Will generate squashfs image for VPNOR" |
| 144 | elif [[ "${image_type}" == "static" ]]; then |
| 145 | echo "Will use static image for PNOR" |
| 146 | else |
| 147 | echo "Please specify the image type, \"squashfs\" or \"static\"" |
| 148 | echo |
| 149 | echo "$help" |
| 150 | exit 1 |
| 151 | fi |
| 152 | |
Michael Tritz | 8f39673 | 2017-06-09 10:55:35 -0500 | [diff] [blame] | 153 | if [[ -z $outfile ]]; then |
| 154 | if [[ ${pnorfile##*.} == "pnor" ]]; then |
Adriana Kobylak | 7bd45a3 | 2021-04-20 19:45:05 +0000 | [diff] [blame] | 155 | outfile=$(pwd)/${pnorfile##*/}.$image_type.tar |
Michael Tritz | 8f39673 | 2017-06-09 10:55:35 -0500 | [diff] [blame] | 156 | else |
Adriana Kobylak | 7bd45a3 | 2021-04-20 19:45:05 +0000 | [diff] [blame] | 157 | outfile=$(pwd)/${pnorfile##*/}.pnor.$image_type.tar |
Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 158 | fi |
| 159 | if [[ "${image_type}" == "static" ]]; then |
| 160 | # Append .gz so the tarball is compressed |
| 161 | outfile=$outfile.gz |
Michael Tritz | 8f39673 | 2017-06-09 10:55:35 -0500 | [diff] [blame] | 162 | fi |
| 163 | else |
| 164 | if [[ $outfile != /* ]]; then |
Adriana Kobylak | 7bd45a3 | 2021-04-20 19:45:05 +0000 | [diff] [blame] | 165 | outfile=$(pwd)/$outfile |
Michael Tritz | 8f39673 | 2017-06-09 10:55:35 -0500 | [diff] [blame] | 166 | fi |
| 167 | fi |
| 168 | |
Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 169 | |
Adriana Kobylak | 7bd45a3 | 2021-04-20 19:45:05 +0000 | [diff] [blame] | 170 | scratch_dir=$(mktemp -d) |
Lei YU | 00d8ade | 2020-01-14 11:30:04 +0800 | [diff] [blame] | 171 | # Remove the temp directory on exit. |
| 172 | # The files in the temp directory may contain read-only files, so add |
| 173 | # --interactive=never to skip the prompt. |
Adriana Kobylak | 7bd45a3 | 2021-04-20 19:45:05 +0000 | [diff] [blame] | 174 | trap '{ rm -r --interactive=never ${scratch_dir}; }' EXIT |
Gunnar Mills | 6b5b27e | 2017-03-01 21:37:01 -0600 | [diff] [blame] | 175 | |
Eddie James | 643e730 | 2018-02-26 15:23:43 -0600 | [diff] [blame] | 176 | if [[ "${do_sign}" == true ]]; then |
| 177 | if [[ -z "${private_key_path}" ]]; then |
| 178 | private_key_path=${scratch_dir}/OpenBMC.priv |
| 179 | echo "${private_key}" > "${private_key_path}" |
| 180 | echo "Image is NOT secure!! Signing with the open private key!" |
| 181 | else |
| 182 | if [[ ! -f "${private_key_path}" ]]; then |
| 183 | echo "Couldn't find private key ${private_key_path}." |
| 184 | exit 1 |
| 185 | fi |
| 186 | |
| 187 | echo "Signing with ${private_key_path}." |
| 188 | fi |
| 189 | |
| 190 | public_key_file=publickey |
| 191 | public_key_path=${scratch_dir}/$public_key_file |
Adriana Kobylak | 7bd45a3 | 2021-04-20 19:45:05 +0000 | [diff] [blame] | 192 | openssl pkey -in "${private_key_path}" -pubout -out "${public_key_path}" |
Eddie James | 643e730 | 2018-02-26 15:23:43 -0600 | [diff] [blame] | 193 | fi |
| 194 | |
Gunnar Mills | 6b5b27e | 2017-03-01 21:37:01 -0600 | [diff] [blame] | 195 | echo "Parsing PNOR TOC..." |
Gunnar Mills | d4908a4 | 2017-03-07 08:25:59 -0600 | [diff] [blame] | 196 | |
Adriana Kobylak | 851bc06 | 2019-06-05 14:33:06 -0500 | [diff] [blame] | 197 | pnor_dir="${scratch_dir}/pnor" |
Adriana Kobylak | 7bd45a3 | 2021-04-20 19:45:05 +0000 | [diff] [blame] | 198 | mkdir "${pnor_dir}" |
Adriana Kobylak | 851bc06 | 2019-06-05 14:33:06 -0500 | [diff] [blame] | 199 | |
Adriana Kobylak | 7bd45a3 | 2021-04-20 19:45:05 +0000 | [diff] [blame] | 200 | pflash --partition=part --read="${pnor_dir}"/part -F "${pnorfile}" |
| 201 | pflash --partition=VERSION --read="${pnor_dir}"/VERSION -F "${pnorfile}" |
| 202 | version_size=$(wc -c "${pnor_dir}"/VERSION | cut -d' ' -f 1) |
| 203 | magic_number=$(xxd -p -l 4 "${pnor_dir}"/VERSION) |
Samuel Mendoza-Jonas | d1d1921 | 2018-06-01 14:02:24 +1000 | [diff] [blame] | 204 | # Check if VERSION is signed. A signed version partition will have an extra |
| 205 | # 4K header starting with the magic number 0x17082011, see: |
| 206 | # https://github.com/open-power/skiboot/blob/master/libstb/container.h#L47 |
Adriana Kobylak | 7bd45a3 | 2021-04-20 19:45:05 +0000 | [diff] [blame] | 207 | if [ "$version_size" == "8192" ] && [ "$magic_number" == "17082011" ]; then |
Samuel Mendoza-Jonas | d1d1921 | 2018-06-01 14:02:24 +1000 | [diff] [blame] | 208 | # Advance past the STB header (4K, indexed from 1) |
Adriana Kobylak | 7bd45a3 | 2021-04-20 19:45:05 +0000 | [diff] [blame] | 209 | cp "${pnor_dir}"/VERSION "${pnor_dir}"/VERSION_FULL |
| 210 | tail --bytes=+4097 "${pnor_dir}"/VERSION_FULL > "${pnor_dir}"/VERSION |
Samuel Mendoza-Jonas | d1d1921 | 2018-06-01 14:02:24 +1000 | [diff] [blame] | 211 | fi |
Gunnar Mills | 6b5b27e | 2017-03-01 21:37:01 -0600 | [diff] [blame] | 212 | { |
Adriana Kobylak | 7bd45a3 | 2021-04-20 19:45:05 +0000 | [diff] [blame] | 213 | version=$(head -n 1 "${pnor_dir}"/VERSION) |
Gunnar Mills | 2f27b74 | 2017-03-20 13:46:30 -0500 | [diff] [blame] | 214 | echo "version=$version" |
Adriana Kobylak | 7bd45a3 | 2021-04-20 19:45:05 +0000 | [diff] [blame] | 215 | # shellcheck disable=SC2005,SC2046 # Need the echo to remove new lines, same |
| 216 | # reason for not quoting the tail command |
| 217 | extended_version=$(echo $(tail -n +2 "${pnor_dir}"/VERSION)|tr ' ' ',') |
Saqib Khan | 029b825 | 2017-03-22 21:38:07 -0500 | [diff] [blame] | 218 | echo "extended_version=$extended_version" |
Adriana Kobylak | 7bd45a3 | 2021-04-20 19:45:05 +0000 | [diff] [blame] | 219 | while read -r line; do |
Gunnar Mills | 6b5b27e | 2017-03-01 21:37:01 -0600 | [diff] [blame] | 220 | if [[ $line == "ID="* ]]; then |
Gunnar Mills | e0ed302 | 2017-03-02 16:16:19 -0600 | [diff] [blame] | 221 | # This line looks like |
| 222 | # "ID=05 MVPD 000d9000..00169000 (actual=00090000) [ECC]" |
Gunnar Mills | 6b5b27e | 2017-03-01 21:37:01 -0600 | [diff] [blame] | 223 | read -r -a fields <<< "$line" |
Gunnar Mills | e0ed302 | 2017-03-02 16:16:19 -0600 | [diff] [blame] | 224 | |
Gunnar Mills | d4908a4 | 2017-03-07 08:25:59 -0600 | [diff] [blame] | 225 | id=${fields[0]##*=} |
Adriana Kobylak | 7bd45a3 | 2021-04-20 19:45:05 +0000 | [diff] [blame] | 226 | offset=$((ffs_entry_size * 10#${id} + vercheck_offset)) |
| 227 | vercheck=$(xxd -p -l 0x1 -seek ${offset} "${pnor_dir}"/part) |
| 228 | # shellcheck disable=SC2155 # Need the export in the same line to avoid |
| 229 | # pflash error |
| 230 | export flags=$(pflash --detail=$((10#$id)) -F "${pnorfile}" | grep "\[" | |
Michael Tritz | 1bd65ac | 2017-05-07 17:40:14 -0500 | [diff] [blame] | 231 | sed 's/....$//' | tr '\n' ',' | sed 's/.$//') |
| 232 | if [[ $flags != "" ]]; then |
| 233 | flags=,$flags |
| 234 | fi |
| 235 | |
Adriana Kobylak | 7bd45a3 | 2021-04-20 19:45:05 +0000 | [diff] [blame] | 236 | if [[ $(echo "$flags" | grep "READONLY") == "" && |
| 237 | $(echo "$flags" | grep "PRESERVED") == "" ]]; then |
Michael Tritz | 1bd65ac | 2017-05-07 17:40:14 -0500 | [diff] [blame] | 238 | flags=$flags,READWRITE |
Gunnar Mills | d4908a4 | 2017-03-07 08:25:59 -0600 | [diff] [blame] | 239 | fi |
| 240 | |
Gunnar Mills | e0ed302 | 2017-03-02 16:16:19 -0600 | [diff] [blame] | 241 | # Need the partition ID, name, start location, end location, and flags |
Adriana Kobylak | 1e4a7f2 | 2017-07-09 16:12:36 -0500 | [diff] [blame] | 242 | echo "partition${id}=${fields[1]},${fields[2]/../,},${vercheck}${flags}" |
Gunnar Mills | d4908a4 | 2017-03-07 08:25:59 -0600 | [diff] [blame] | 243 | |
Gunnar Mills | 6b5b27e | 2017-03-01 21:37:01 -0600 | [diff] [blame] | 244 | # Save the partition name |
Adriana Kobylak | 7bd45a3 | 2021-04-20 19:45:05 +0000 | [diff] [blame] | 245 | partitions+=("${fields[1]}") |
Gunnar Mills | 6b5b27e | 2017-03-01 21:37:01 -0600 | [diff] [blame] | 246 | fi |
Adriana Kobylak | 1e4a7f2 | 2017-07-09 16:12:36 -0500 | [diff] [blame] | 247 | # Don't need the BACKUP_PART partition |
Adriana Kobylak | 7bd45a3 | 2021-04-20 19:45:05 +0000 | [diff] [blame] | 248 | done < <(pflash --info -F "${pnorfile}" | grep -v "BACKUP") |
| 249 | } > "${pnor_dir}"/${tocfile} |
Gunnar Mills | 37751f9 | 2017-02-07 21:05:01 -0600 | [diff] [blame] | 250 | |
Gunnar Mills | 18f7cdb | 2017-02-07 16:44:19 -0600 | [diff] [blame] | 251 | for partition in "${partitions[@]}"; do |
| 252 | echo "Reading ${partition}..." |
Adriana Kobylak | 7bd45a3 | 2021-04-20 19:45:05 +0000 | [diff] [blame] | 253 | pflash --partition="${partition}" \ |
| 254 | --read="${pnor_dir}"/"${partition}" \ |
| 255 | -F "${pnorfile}" |
Gunnar Mills | 18f7cdb | 2017-02-07 16:44:19 -0600 | [diff] [blame] | 256 | done |
Gunnar Mills | 37751f9 | 2017-02-07 21:05:01 -0600 | [diff] [blame] | 257 | |
Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 258 | manifest_location="MANIFEST" |
| 259 | files_to_sign="$manifest_location $public_key_file" |
| 260 | |
| 261 | # Go to scratch_dir |
| 262 | |
| 263 | if [[ "${image_type}" == "squashfs" ]]; then |
| 264 | echo "Creating SquashFS image..." |
Adriana Kobylak | 851bc06 | 2019-06-05 14:33:06 -0500 | [diff] [blame] | 265 | # Prepare pnor file in ${pnor_dir} |
| 266 | cd "${pnor_dir}" |
Adriana Kobylak | 85f2540 | 2019-10-09 13:56:59 -0500 | [diff] [blame] | 267 | # Set permissions of partition files to read only |
Adriana Kobylak | 7bd45a3 | 2021-04-20 19:45:05 +0000 | [diff] [blame] | 268 | chmod 440 -- * |
Adriana Kobylak | 095b1a0 | 2022-05-23 20:44:59 +0000 | [diff] [blame] | 269 | # shellcheck disable=SC2048,SC2086 # Do not quote partitions since it lists |
| 270 | # multiple files and mksquashfs would assume to be a single file name within |
| 271 | # quotes |
Adriana Kobylak | 7bd45a3 | 2021-04-20 19:45:05 +0000 | [diff] [blame] | 272 | mksquashfs ${tocfile} ${partitions[*]} "${scratch_dir}"/pnor.xz.squashfs -all-root |
Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 273 | cd "${scratch_dir}" |
Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 274 | files_to_sign+=" pnor.xz.squashfs" |
| 275 | else |
Adriana Kobylak | 7bd45a3 | 2021-04-20 19:45:05 +0000 | [diff] [blame] | 276 | cp "${pnorfile}" "${scratch_dir}" |
Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 277 | cd "${scratch_dir}" |
Adriana Kobylak | 7bd45a3 | 2021-04-20 19:45:05 +0000 | [diff] [blame] | 278 | files_to_sign+=" $(basename "${pnorfile}")" |
Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 279 | fi |
Gunnar Mills | 37751f9 | 2017-02-07 21:05:01 -0600 | [diff] [blame] | 280 | |
Saqib Khan | 93433f0 | 2017-03-23 22:24:27 -0500 | [diff] [blame] | 281 | echo "Creating MANIFEST for the image" |
Leonel Gonzalez | c14a3d2 | 2017-06-22 12:49:38 -0500 | [diff] [blame] | 282 | 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] | 283 | extended_version=$extended_version" >> $manifest_location |
Saqib Khan | 93433f0 | 2017-03-23 22:24:27 -0500 | [diff] [blame] | 284 | |
Adriana Kobylak | 7bd45a3 | 2021-04-20 19:45:05 +0000 | [diff] [blame] | 285 | if [[ -n "${machine_name}" ]]; then |
Lei YU | 647d613 | 2019-12-31 14:35:00 +0800 | [diff] [blame] | 286 | echo -e "MachineName=${machine_name}" >> $manifest_location |
| 287 | fi |
| 288 | |
Eddie James | 643e730 | 2018-02-26 15:23:43 -0600 | [diff] [blame] | 289 | if [[ "${do_sign}" == true ]]; then |
| 290 | private_key_name=$(basename "${private_key_path}") |
| 291 | key_type="${private_key_name%.*}" |
| 292 | echo KeyType="${key_type}" >> $manifest_location |
| 293 | echo HashType="RSA-SHA256" >> $manifest_location |
| 294 | |
Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 295 | for file in $files_to_sign; do |
Adriana Kobylak | 7bd45a3 | 2021-04-20 19:45:05 +0000 | [diff] [blame] | 296 | openssl dgst -sha256 -sign "${private_key_path}" -out "${file}.sig" "$file" |
Eddie James | 643e730 | 2018-02-26 15:23:43 -0600 | [diff] [blame] | 297 | done |
| 298 | |
Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 299 | additional_files="*.sig" |
Eddie James | 643e730 | 2018-02-26 15:23:43 -0600 | [diff] [blame] | 300 | fi |
| 301 | |
Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 302 | if [[ "${image_type}" == "squashfs" ]]; then |
| 303 | echo "Generating tarball to contain the SquashFS image and its MANIFEST" |
Adriana Kobylak | 7bd45a3 | 2021-04-20 19:45:05 +0000 | [diff] [blame] | 304 | # shellcheck disable=SC2086 # Do not quote the files variables since they list |
| 305 | # multiple files and tar would assume to be a single file name within quotes |
| 306 | tar -cvf "$outfile" $files_to_sign $additional_files |
Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 307 | echo "SquashFSTarball at ${outfile}" |
| 308 | else |
Adriana Kobylak | 7bd45a3 | 2021-04-20 19:45:05 +0000 | [diff] [blame] | 309 | # shellcheck disable=SC2086 # Do not quote the files variables since they list |
| 310 | # multiple files and tar would assume to be a single file name within quotes |
| 311 | tar -czvf "$outfile" $files_to_sign $additional_files |
Lei YU | dcb3fd7 | 2019-02-21 13:19:03 +0800 | [diff] [blame] | 312 | echo "Static layout tarball at $outfile" |
| 313 | fi |