blob: ce7e0a8d5f70624b72f803722b99c04118b859a2 [file] [log] [blame]
Gunnar Mills6b5b27e2017-03-01 21:37:01 -06001#!/bin/bash
Gunnar Millsf8f11302017-03-08 13:11:33 -06002set -eo pipefail
Gunnar Millse8221902017-02-03 15:59:06 -06003
Lei YUdcb3fd72019-02-21 13:19:03 +08004help=$'Generate Tarball with PNOR image and MANIFEST Script
Gunnar Millse8221902017-02-03 15:59:06 -06005
Lei YUdcb3fd72019-02-21 13:19:03 +08006Generates a PNOR SquashFS image from the PNOR image for VPNOR,
7Or use a static layout raw PNOR image,
Gunnar Mills29414352017-10-25 11:07:43 -05008Creates a MANIFEST for image verification and recreation
Lei YUdcb3fd72019-02-21 13:19:03 +08009Packages the image and MANIFEST together in a tarball
Gunnar Millse8221902017-02-03 15:59:06 -060010
Lei YUdcb3fd72019-02-21 13:19:03 +080011usage: generate-tar [OPTION] <PNOR FILE>...
Gunnar Millse8221902017-02-03 15:59:06 -060012
13Options:
Patrick Williams15513db2022-12-08 06:23:24 -060014-i, --image <squashfs|static>
15Generate 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
18unspecified.
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
25the private key file. Defaults to the bash variable
26PRIVATE_KEY_PATH if available, or else uses the
27open-source private key in this script.
28-m, --machine <name> Optionally specify the target machine name of this
29image.
30-h, --help Display this help text and exit.
Gunnar Millse8221902017-02-03 15:59:06 -060031'
Eddie James643e7302018-02-26 15:23:43 -060032
33private_key=$'-----BEGIN PRIVATE KEY-----
Rashmica Guptacb3de142024-07-05 15:50:40 +100034MIIJRAIBADANBgkqhkiG9w0BAQEFAASCCS4wggkqAgEAAoICAQDO7vWM6ZOylO6T
35lxDiRWgKCFau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86
Adriana Kobylak1e4a7f22017-07-09 16:12:36 -050087# 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 Kobylak7bd45a32021-04-20 19:45:05 +000090ffs_entry_size=128
91vercheck_offset=112
Eddie James643e7302018-02-26 15:23:43 -060092do_sign=false
Adriana Kobylak7bd45a32021-04-20 19:45:05 +000093PRIVATE_KEY_PATH=${PRIVATE_KEY_PATH:-}
Eddie James643e7302018-02-26 15:23:43 -060094private_key_path="${PRIVATE_KEY_PATH}"
Lei YUdcb3fd72019-02-21 13:19:03 +080095image_type=""
Michael Tritz8f396732017-06-09 10:55:35 -050096outfile=""
Gunnar Mills6b5b27e2017-03-01 21:37:01 -060097declare -a partitions=()
98tocfile="pnor.toc"
Lei YU647d6132019-12-31 14:35:00 +080099machine_name=""
Gunnar Mills37751f92017-02-07 21:05:01 -0600100
Gunnar Millse8221902017-02-03 15:59:06 -0600101while [[ $# -gt 0 ]]; do
102 key="$1"
103 case $key in
Lei YUdcb3fd72019-02-21 13:19:03 +0800104 -i|--image)
105 image_type="$2"
106 shift 2
107 ;;
Gunnar Mills37751f92017-02-07 21:05:01 -0600108 -f|--file)
109 outfile="$2"
110 shift 2
111 ;;
Eddie James643e7302018-02-26 15:23:43 -0600112 -s|--sign)
113 do_sign=true
Adriana Kobylak7bd45a32021-04-20 19:45:05 +0000114 if [[ -n "${2}" && "${2}" != -* ]]; then
Eddie James643e7302018-02-26 15:23:43 -0600115 private_key_path="$2"
116 shift 2
117 else
118 shift 1
119 fi
120 ;;
Lei YU647d6132019-12-31 14:35:00 +0800121 -m|--machine)
122 machine_name="$2"
123 shift 2
124 ;;
Gunnar Millse8221902017-02-03 15:59:06 -0600125 -h|--help)
126 echo "$help"
127 exit
128 ;;
129 *)
Gunnar Millsc15b02d2017-03-03 10:28:37 -0600130 pnorfile="$1"
131 shift 1
Gunnar Millse8221902017-02-03 15:59:06 -0600132 ;;
133 esac
134done
Gunnar Mills18f7cdb2017-02-07 16:44:19 -0600135
Gunnar Millsc15b02d2017-03-03 10:28:37 -0600136if [ ! -f "${pnorfile}" ]; then
137 echo "Please enter a valid PNOR file."
138 echo "$help"
139 exit 1
140fi
141
Lei YUdcb3fd72019-02-21 13:19:03 +0800142if [[ "${image_type}" == "squashfs" ]]; then
143 echo "Will generate squashfs image for VPNOR"
144elif [[ "${image_type}" == "static" ]]; then
145 echo "Will use static image for PNOR"
146else
147 echo "Please specify the image type, \"squashfs\" or \"static\""
148 echo
149 echo "$help"
150 exit 1
151fi
152
Michael Tritz8f396732017-06-09 10:55:35 -0500153if [[ -z $outfile ]]; then
154 if [[ ${pnorfile##*.} == "pnor" ]]; then
Adriana Kobylak7bd45a32021-04-20 19:45:05 +0000155 outfile=$(pwd)/${pnorfile##*/}.$image_type.tar
Michael Tritz8f396732017-06-09 10:55:35 -0500156 else
Adriana Kobylak7bd45a32021-04-20 19:45:05 +0000157 outfile=$(pwd)/${pnorfile##*/}.pnor.$image_type.tar
Lei YUdcb3fd72019-02-21 13:19:03 +0800158 fi
159 if [[ "${image_type}" == "static" ]]; then
160 # Append .gz so the tarball is compressed
161 outfile=$outfile.gz
Michael Tritz8f396732017-06-09 10:55:35 -0500162 fi
163else
164 if [[ $outfile != /* ]]; then
Adriana Kobylak7bd45a32021-04-20 19:45:05 +0000165 outfile=$(pwd)/$outfile
Michael Tritz8f396732017-06-09 10:55:35 -0500166 fi
167fi
168
Lei YUdcb3fd72019-02-21 13:19:03 +0800169
Adriana Kobylak7bd45a32021-04-20 19:45:05 +0000170scratch_dir=$(mktemp -d)
Lei YU00d8ade2020-01-14 11:30:04 +0800171# 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 Kobylak7bd45a32021-04-20 19:45:05 +0000174trap '{ rm -r --interactive=never ${scratch_dir}; }' EXIT
Gunnar Mills6b5b27e2017-03-01 21:37:01 -0600175
Eddie James643e7302018-02-26 15:23:43 -0600176if [[ "${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 Kobylak7bd45a32021-04-20 19:45:05 +0000192 openssl pkey -in "${private_key_path}" -pubout -out "${public_key_path}"
Eddie James643e7302018-02-26 15:23:43 -0600193fi
194
Gunnar Mills6b5b27e2017-03-01 21:37:01 -0600195echo "Parsing PNOR TOC..."
Gunnar Millsd4908a42017-03-07 08:25:59 -0600196
Adriana Kobylak851bc062019-06-05 14:33:06 -0500197pnor_dir="${scratch_dir}/pnor"
Adriana Kobylak7bd45a32021-04-20 19:45:05 +0000198mkdir "${pnor_dir}"
Adriana Kobylak851bc062019-06-05 14:33:06 -0500199
Adriana Kobylak7bd45a32021-04-20 19:45:05 +0000200pflash --partition=part --read="${pnor_dir}"/part -F "${pnorfile}"
201pflash --partition=VERSION --read="${pnor_dir}"/VERSION -F "${pnorfile}"
202version_size=$(wc -c "${pnor_dir}"/VERSION | cut -d' ' -f 1)
203magic_number=$(xxd -p -l 4 "${pnor_dir}"/VERSION)
Samuel Mendoza-Jonasd1d19212018-06-01 14:02:24 +1000204# 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 Kobylak7bd45a32021-04-20 19:45:05 +0000207if [ "$version_size" == "8192" ] && [ "$magic_number" == "17082011" ]; then
Samuel Mendoza-Jonasd1d19212018-06-01 14:02:24 +1000208 # Advance past the STB header (4K, indexed from 1)
Adriana Kobylak7bd45a32021-04-20 19:45:05 +0000209 cp "${pnor_dir}"/VERSION "${pnor_dir}"/VERSION_FULL
210 tail --bytes=+4097 "${pnor_dir}"/VERSION_FULL > "${pnor_dir}"/VERSION
Samuel Mendoza-Jonasd1d19212018-06-01 14:02:24 +1000211fi
Gunnar Mills6b5b27e2017-03-01 21:37:01 -0600212{
Adriana Kobylak7bd45a32021-04-20 19:45:05 +0000213 version=$(head -n 1 "${pnor_dir}"/VERSION)
Gunnar Mills2f27b742017-03-20 13:46:30 -0500214 echo "version=$version"
Adriana Kobylak7bd45a32021-04-20 19:45:05 +0000215 # 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 Khan029b8252017-03-22 21:38:07 -0500218 echo "extended_version=$extended_version"
Adriana Kobylak7bd45a32021-04-20 19:45:05 +0000219 while read -r line; do
Gunnar Mills6b5b27e2017-03-01 21:37:01 -0600220 if [[ $line == "ID="* ]]; then
Gunnar Millse0ed3022017-03-02 16:16:19 -0600221 # This line looks like
222 # "ID=05 MVPD 000d9000..00169000 (actual=00090000) [ECC]"
Gunnar Mills6b5b27e2017-03-01 21:37:01 -0600223 read -r -a fields <<< "$line"
Gunnar Millse0ed3022017-03-02 16:16:19 -0600224
Gunnar Millsd4908a42017-03-07 08:25:59 -0600225 id=${fields[0]##*=}
Adriana Kobylak7bd45a32021-04-20 19:45:05 +0000226 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 Tritz1bd65ac2017-05-07 17:40:14 -0500231 sed 's/....$//' | tr '\n' ',' | sed 's/.$//')
232 if [[ $flags != "" ]]; then
233 flags=,$flags
234 fi
235
Adriana Kobylak7bd45a32021-04-20 19:45:05 +0000236 if [[ $(echo "$flags" | grep "READONLY") == "" &&
237 $(echo "$flags" | grep "PRESERVED") == "" ]]; then
Michael Tritz1bd65ac2017-05-07 17:40:14 -0500238 flags=$flags,READWRITE
Gunnar Millsd4908a42017-03-07 08:25:59 -0600239 fi
240
Gunnar Millse0ed3022017-03-02 16:16:19 -0600241 # Need the partition ID, name, start location, end location, and flags
Adriana Kobylak1e4a7f22017-07-09 16:12:36 -0500242 echo "partition${id}=${fields[1]},${fields[2]/../,},${vercheck}${flags}"
Gunnar Millsd4908a42017-03-07 08:25:59 -0600243
Gunnar Mills6b5b27e2017-03-01 21:37:01 -0600244 # Save the partition name
Adriana Kobylak7bd45a32021-04-20 19:45:05 +0000245 partitions+=("${fields[1]}")
Gunnar Mills6b5b27e2017-03-01 21:37:01 -0600246 fi
Adriana Kobylak1e4a7f22017-07-09 16:12:36 -0500247 # Don't need the BACKUP_PART partition
Adriana Kobylak7bd45a32021-04-20 19:45:05 +0000248 done < <(pflash --info -F "${pnorfile}" | grep -v "BACKUP")
249} > "${pnor_dir}"/${tocfile}
Gunnar Mills37751f92017-02-07 21:05:01 -0600250
Gunnar Mills18f7cdb2017-02-07 16:44:19 -0600251for partition in "${partitions[@]}"; do
252 echo "Reading ${partition}..."
Adriana Kobylak7bd45a32021-04-20 19:45:05 +0000253 pflash --partition="${partition}" \
254 --read="${pnor_dir}"/"${partition}" \
255 -F "${pnorfile}"
Gunnar Mills18f7cdb2017-02-07 16:44:19 -0600256done
Gunnar Mills37751f92017-02-07 21:05:01 -0600257
Lei YUdcb3fd72019-02-21 13:19:03 +0800258manifest_location="MANIFEST"
259files_to_sign="$manifest_location $public_key_file"
260
261# Go to scratch_dir
262
263if [[ "${image_type}" == "squashfs" ]]; then
264 echo "Creating SquashFS image..."
Adriana Kobylak851bc062019-06-05 14:33:06 -0500265 # Prepare pnor file in ${pnor_dir}
266 cd "${pnor_dir}"
Adriana Kobylak85f25402019-10-09 13:56:59 -0500267 # Set permissions of partition files to read only
Adriana Kobylak7bd45a32021-04-20 19:45:05 +0000268 chmod 440 -- *
Adriana Kobylak095b1a02022-05-23 20:44:59 +0000269 # 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 Kobylak7bd45a32021-04-20 19:45:05 +0000272 mksquashfs ${tocfile} ${partitions[*]} "${scratch_dir}"/pnor.xz.squashfs -all-root
Lei YUdcb3fd72019-02-21 13:19:03 +0800273 cd "${scratch_dir}"
Lei YUdcb3fd72019-02-21 13:19:03 +0800274 files_to_sign+=" pnor.xz.squashfs"
275else
Adriana Kobylak7bd45a32021-04-20 19:45:05 +0000276 cp "${pnorfile}" "${scratch_dir}"
Lei YUdcb3fd72019-02-21 13:19:03 +0800277 cd "${scratch_dir}"
Adriana Kobylak7bd45a32021-04-20 19:45:05 +0000278 files_to_sign+=" $(basename "${pnorfile}")"
Lei YUdcb3fd72019-02-21 13:19:03 +0800279fi
Gunnar Mills37751f92017-02-07 21:05:01 -0600280
Saqib Khan93433f02017-03-23 22:24:27 -0500281echo "Creating MANIFEST for the image"
Leonel Gonzalezc14a3d22017-06-22 12:49:38 -0500282echo -e "purpose=xyz.openbmc_project.Software.Version.VersionPurpose.Host\nversion=$version\n\
Saqib Khan7254f0e2017-04-10 21:45:37 -0500283extended_version=$extended_version" >> $manifest_location
Saqib Khan93433f02017-03-23 22:24:27 -0500284
Adriana Kobylak7bd45a32021-04-20 19:45:05 +0000285if [[ -n "${machine_name}" ]]; then
Lei YU647d6132019-12-31 14:35:00 +0800286 echo -e "MachineName=${machine_name}" >> $manifest_location
287fi
288
Eddie James643e7302018-02-26 15:23:43 -0600289if [[ "${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 YUdcb3fd72019-02-21 13:19:03 +0800295 for file in $files_to_sign; do
Adriana Kobylak7bd45a32021-04-20 19:45:05 +0000296 openssl dgst -sha256 -sign "${private_key_path}" -out "${file}.sig" "$file"
Eddie James643e7302018-02-26 15:23:43 -0600297 done
298
Lei YUdcb3fd72019-02-21 13:19:03 +0800299 additional_files="*.sig"
Eddie James643e7302018-02-26 15:23:43 -0600300fi
301
Lei YUdcb3fd72019-02-21 13:19:03 +0800302if [[ "${image_type}" == "squashfs" ]]; then
303 echo "Generating tarball to contain the SquashFS image and its MANIFEST"
Adriana Kobylak7bd45a32021-04-20 19:45:05 +0000304 # 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 YUdcb3fd72019-02-21 13:19:03 +0800307 echo "SquashFSTarball at ${outfile}"
308else
Adriana Kobylak7bd45a32021-04-20 19:45:05 +0000309 # 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 YUdcb3fd72019-02-21 13:19:03 +0800312 echo "Static layout tarball at $outfile"
313fi