Initial commit
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
SUMMARY = "Dummy image uploader for sending debug binaries"
|
||||
DESCRIPTION = "Dummy image uploader for sending debug binaries"
|
||||
PR = "r1"
|
||||
|
||||
LICENSE = "Apache-2.0"
|
||||
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
|
||||
|
||||
inherit systemd
|
||||
|
||||
SRC_URI += "file://config-dummy.json"
|
||||
SRC_URI += "file://dummy-verify.service"
|
||||
|
||||
FILES:${PN} += "${datadir}/phosphor-ipmi-flash"
|
||||
|
||||
SYSTEMD_SERVICE:${PN} += "dummy-verify.service"
|
||||
|
||||
do_install() {
|
||||
install -d ${D}${datadir}/phosphor-ipmi-flash
|
||||
install -m 0644 ${WORKDIR}/config-dummy.json ${D}${datadir}/phosphor-ipmi-flash
|
||||
|
||||
install -d ${D}${systemd_system_unitdir}
|
||||
install -m 0644 ${WORKDIR}/dummy-verify.service ${D}${systemd_system_unitdir}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
[{
|
||||
"blob": "/flash/dummy",
|
||||
"handler": {
|
||||
"type": "file",
|
||||
"path": "/run/initramfs/bmc-image"
|
||||
},
|
||||
"actions": {
|
||||
"preparation": {
|
||||
"type": "skip"
|
||||
},
|
||||
"verification": {
|
||||
"type": "systemd",
|
||||
"unit": "dummy-verify.service"
|
||||
},
|
||||
"update": {
|
||||
"type": "skip"
|
||||
}
|
||||
}
|
||||
}]
|
||||
@@ -0,0 +1,6 @@
|
||||
[Unit]
|
||||
Description=Dummy flash file verification
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/bin/mv /run/initramfs/bmc-image /run/initramfs/dummy
|
||||
@@ -0,0 +1,20 @@
|
||||
SUMMARY = "Google BMC Update Utilities"
|
||||
DESCRIPTION = "Google BMC Update Utilities"
|
||||
PR = "r1"
|
||||
|
||||
LICENSE = "Apache-2.0"
|
||||
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
|
||||
|
||||
SRC_URI += " \
|
||||
file://40-gbmc-upgrade.sh \
|
||||
"
|
||||
|
||||
FILES:${PN} += "${datadir}/gbmc-br-dhcp"
|
||||
|
||||
RDEPENDS:${PN} += "curl"
|
||||
RDEPENDS:${PN} += "tar"
|
||||
|
||||
do_install() {
|
||||
install -d ${D}${datadir}/gbmc-br-dhcp
|
||||
install -m 0644 ${WORKDIR}/40-gbmc-upgrade.sh ${D}${datadir}/gbmc-br-dhcp/
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
#!/bin/bash
|
||||
# Copyright 2021 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
[ -z "${gbmc_upgrade-}" ] || exit
|
||||
|
||||
: "${GBMC_UPGRADE_SIG=/tmp/bmc.sig}"
|
||||
|
||||
GBMC_UPGRADE_UNPACK_FILES=()
|
||||
# shellcheck disable=SC2034
|
||||
GBMC_UPGRADE_HOOKS=(gbmc_upgrade_internal)
|
||||
|
||||
if machine="$(source /etc/os-release && echo "$GBMC_TARGET_MACHINE")"; then
|
||||
GBMC_UPGRADE_UNPACK_FILES+=("*/firmware-gbmc/$machine")
|
||||
else
|
||||
echo 'Failed to find GBMC machine type from /etc/os-release' >&2
|
||||
fi
|
||||
|
||||
gbmc_upgrade_dl_unpack() {
|
||||
echo "Fetching $bootfile_url" >&2
|
||||
|
||||
# We only support tarballs at the moment, our URLs will always denote
|
||||
# this with a URI query param of `format=TAR`.
|
||||
local tflags=()
|
||||
if [[ "$bootfile_url" =~ [\&?]format=TAR(_GZIP)?(&|$) ]]; then
|
||||
local t="${BASH_REMATCH[1]}"
|
||||
[ "$t" = '_GZIP' ] && tflags+=('-z')
|
||||
else
|
||||
echo "Unknown upgrade unpack method: $bootfile_url" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Ensure some sane output file limit
|
||||
# Currently no BMC image is larger than 64M
|
||||
# We want to allow 2 images and a small amount of metadata (2*64+2)M
|
||||
local max_mb=$((2*64 + 2))
|
||||
ulimit -f $((max_mb * 1024 * 1024 / 512)) || return
|
||||
timeout=$((SECONDS + 300))
|
||||
stime=5
|
||||
while true; do
|
||||
local st=()
|
||||
curl -LSsk --max-time $((timeout - SECONDS)) "$bootfile_url" |
|
||||
tar "${tflags[@]}" --wildcards -xC "$tmpdir" "${GBMC_UPGRADE_UNPACK_FILES[@]}" 2>"$tmpdir"/tarerr \
|
||||
&& st=("${PIPESTATUS[@]}") || st=("${PIPESTATUS[@]}")
|
||||
# Curl failures should continue
|
||||
if (( st[0] == 0 )); then
|
||||
# Tar failures when curl succeeds are hard errors to start over.
|
||||
# shellcheck disable=SC2143
|
||||
if (( st[1] != 0 )) && [[ -n $(grep -v '\(Exiting with failure status\|Not found in archive\|Cannot hard link\)' "$tmpdir"/tarerr) ]]; then
|
||||
echo 'Unpacking failed' >&2
|
||||
return 1
|
||||
fi
|
||||
# Success should continue without retry
|
||||
break
|
||||
fi
|
||||
if (( SECONDS + stime >= timeout )); then
|
||||
echo 'Timed out fetching image' >&2
|
||||
return 1
|
||||
fi
|
||||
(shopt -s nullglob dotglob; rm -rf -- "${tmpdir:?}"/*)
|
||||
sleep $stime
|
||||
done
|
||||
}
|
||||
|
||||
gbmc_upgrade_hook() {
|
||||
[ -n "${bootfile_url-}" ] || return 0
|
||||
|
||||
local tmpdir
|
||||
tmpdir="$(mktemp -d)" || return
|
||||
# shellcheck disable=SC2015
|
||||
gbmc_upgrade_dl_unpack && gbmc_br_run_hooks GBMC_UPGRADE_HOOKS || true
|
||||
# shellcheck disable=SC2153
|
||||
rm -rf -- "$tmpdir" "$GBMC_UPGRADE_SIG" "$GBMC_UPGRADE_IMG"
|
||||
}
|
||||
|
||||
gbmc_upgrade_fetch() (
|
||||
local sig
|
||||
sig="$(find "$tmpdir" -name 'image-*.sig' | head -n 1)" || return
|
||||
local img="${sig%.sig}"
|
||||
mv "$sig" "$GBMC_UPGRADE_SIG" || return
|
||||
mv "$img" "$GBMC_UPGRADE_IMG" || return
|
||||
|
||||
# Regular packages have a VERSION file with the image
|
||||
local imgdir="${sig%/*}"
|
||||
if [ -f "$imgdir/VERSION" ]; then
|
||||
cat "$imgdir/VERSION" || return
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Staging packages have a directory named after the version
|
||||
local vdir="${imgdir##*/}"
|
||||
if [[ "$vdir" =~ ([0-9]+[.]){3}[0-9]+ ]]; then
|
||||
echo "$vdir"
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
)
|
||||
|
||||
GBMC_BR_DHCP_HOOKS+=(gbmc_upgrade_hook)
|
||||
|
||||
gbmc_upgrade=1
|
||||
@@ -0,0 +1,26 @@
|
||||
SUMMARY = "Google Key installation Script"
|
||||
DESCRIPTION = "Google Key installation Script"
|
||||
PR = "r1"
|
||||
|
||||
LICENSE = "Apache-2.0"
|
||||
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
|
||||
|
||||
RDEPENDS:${PN} += "bash"
|
||||
RDEPENDS:${PN} += "gnupg-gpg"
|
||||
|
||||
SRC_URI += " \
|
||||
file://platforms_gbmc_bringup.gpg \
|
||||
file://platforms_gbmc_secure.gpg \
|
||||
file://verify-bmc-image.sh \
|
||||
"
|
||||
|
||||
do_install() {
|
||||
# Install keys into image.
|
||||
install -d -m 0755 ${D}${datadir}/google-key
|
||||
install -m 0644 ${WORKDIR}/platforms_gbmc_secure.gpg ${D}${datadir}/google-key/prod.key
|
||||
install -m 0644 ${WORKDIR}/platforms_gbmc_bringup.gpg ${D}${datadir}/google-key/dev.key
|
||||
|
||||
# Install the verification helper
|
||||
install -d -m 0755 ${D}${bindir}
|
||||
install -m 0755 ${WORKDIR}/verify-bmc-image.sh ${D}${bindir}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,64 @@
|
||||
#!/bin/bash
|
||||
# Copyright 2021 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
help_out() {
|
||||
echo "$ARG0 [--allow-dev] <image file> <sig file>" >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
opts="$(getopt -o 'd' -l 'allow-dev' -- "$@")" || exit
|
||||
dev=
|
||||
eval set -- "$opts"
|
||||
while true; do
|
||||
case "$1" in
|
||||
--allow-dev|-d)
|
||||
dev=1
|
||||
shift
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo "Bad option: $1" >&2
|
||||
help_out
|
||||
;;
|
||||
esac
|
||||
done
|
||||
image_file="${1?Missing image file}" || help_out
|
||||
sig_file="${2?Missing sig file}" || help_out
|
||||
|
||||
# gnupg needs a home directory even though we don't want to persist any
|
||||
# information. We always make a new temporary directory for this
|
||||
GNUPGHOME=
|
||||
cleanup() {
|
||||
test -n "$GNUPGHOME" && rm -rf "$GNUPGHOME"
|
||||
}
|
||||
trap cleanup ERR EXIT INT
|
||||
GNUPGHOME="$(mktemp -d)" || exit
|
||||
export GNUPGHOME
|
||||
|
||||
gpg() {
|
||||
command gpg --batch --allow-non-selfsigned-uid --no-tty "$@"
|
||||
}
|
||||
import_key() {
|
||||
gpg --import "/usr/share/google-key/$1.key"
|
||||
}
|
||||
|
||||
import_key prod
|
||||
if [ -n "$dev" ]; then
|
||||
import_key dev
|
||||
fi
|
||||
gpg --verify --ignore-time-conflict "$sig_file" "$image_file"
|
||||
@@ -0,0 +1,52 @@
|
||||
SUMMARY = "Google BMC Inplace Update Script"
|
||||
DESCRIPTION = "Google BMC Inplace Update Script"
|
||||
PR = "r1"
|
||||
|
||||
LICENSE = "Apache-2.0"
|
||||
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
|
||||
|
||||
inherit obmc-phosphor-systemd
|
||||
|
||||
PROVIDES += "virtual/bmc-update"
|
||||
RPROVIDES:${PN} += "virtual/bmc-update"
|
||||
|
||||
RDEPENDS:${PN} += " \
|
||||
bash \
|
||||
gbmc-update \
|
||||
google-key \
|
||||
"
|
||||
|
||||
SRC_URI += " \
|
||||
file://config-bmc.json \
|
||||
file://inplace-gbmc-verify.service \
|
||||
file://inplace-gbmc-verify.sh \
|
||||
file://inplace-gbmc-version.service \
|
||||
file://inplace-gbmc-version.sh \
|
||||
file://40-inplace-gbmc-upgrade.sh \
|
||||
"
|
||||
|
||||
SYSTEMD_SERVICE:${PN} += "inplace-gbmc-verify.service"
|
||||
SYSTEMD_SERVICE:${PN} += "inplace-gbmc-version.service"
|
||||
|
||||
FILES:${PN} += "${datadir}/phosphor-ipmi-flash"
|
||||
FILES:${PN} += "${datadir}/gbmc-br-dhcp"
|
||||
|
||||
do_install() {
|
||||
sed -i 's,@ALLOW_DEV@,,' ${WORKDIR}/inplace-gbmc-verify.sh
|
||||
|
||||
install -d ${D}${bindir}
|
||||
install -m 0755 ${WORKDIR}/*.sh ${D}${bindir}
|
||||
|
||||
install -d ${D}${systemd_system_unitdir}
|
||||
install -m 0644 ${WORKDIR}/*.service ${D}${systemd_system_unitdir}
|
||||
|
||||
install -d ${D}${datadir}/phosphor-ipmi-flash
|
||||
install -m 0644 ${WORKDIR}/config-bmc.json ${D}${datadir}/phosphor-ipmi-flash
|
||||
|
||||
install -d ${D}${datadir}/gbmc-br-dhcp
|
||||
install -m 0644 ${WORKDIR}/40-inplace-gbmc-upgrade.sh ${D}${datadir}/gbmc-br-dhcp/
|
||||
}
|
||||
|
||||
do_install:prepend:dev() {
|
||||
sed -i 's,@ALLOW_DEV@,--allow-dev,' ${WORKDIR}/inplace-gbmc-verify.sh
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/bin/bash
|
||||
# Copyright 2021 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
[ -z "${inplace_gbmc_upgrade-}" ] || exit
|
||||
|
||||
# SC doesn't know another file depends on this variable
|
||||
# shellcheck disable=SC2034
|
||||
GBMC_UPGRADE_IMG=/run/initramfs/bmc-image
|
||||
|
||||
gbmc_upgrade_internal() {
|
||||
local version
|
||||
version="$(gbmc_upgrade_fetch)" || return
|
||||
|
||||
echo "IMG Version: $version" >&2
|
||||
local active_version
|
||||
active_version="$(inplace-gbmc-version.sh)" || return
|
||||
echo "Active Version: $active_version" >&2
|
||||
if [[ "$version" == "$active_version" ]]; then
|
||||
echo 'Version already active' >&2
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo 'Verifying image' >&2
|
||||
systemctl start inplace-gbmc-verify || return
|
||||
echo 'Rebooting to perform update' >&2
|
||||
reboot || return
|
||||
# Ensure that we don't "complete" the netboot process until
|
||||
# after the update completes
|
||||
exit 0
|
||||
}
|
||||
|
||||
inplace_gbmc_upgrade=1
|
||||
@@ -0,0 +1,33 @@
|
||||
[{
|
||||
"blob": "/flash/image",
|
||||
"version": {
|
||||
"handler": {
|
||||
"type": "file",
|
||||
"path": "/run/inplace-gbmc-version"
|
||||
},
|
||||
"actions":{
|
||||
"open": {
|
||||
"type": "systemd",
|
||||
"unit": "inplace-gbmc-version.service"
|
||||
}
|
||||
}
|
||||
},
|
||||
"handler": {
|
||||
"type": "file",
|
||||
"path": "/run/initramfs/bmc-image"
|
||||
},
|
||||
"actions": {
|
||||
"preparation": {
|
||||
"type": "skip"
|
||||
},
|
||||
"verification": {
|
||||
"type": "systemd",
|
||||
"unit": "inplace-gbmc-verify.service"
|
||||
},
|
||||
"update": {
|
||||
"type": "systemd",
|
||||
"unit": "reboot.target",
|
||||
"mode": "replace-irreversibly"
|
||||
}
|
||||
}
|
||||
}]
|
||||
@@ -0,0 +1,6 @@
|
||||
[Unit]
|
||||
Description=Verify the Flash Image File
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/inplace-gbmc-verify.sh
|
||||
@@ -0,0 +1,56 @@
|
||||
#!/bin/bash
|
||||
# Copyright 2021 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
# This script will check the signature for the BMC image against
|
||||
# the baked in keyring available. If any aspect of this fails,
|
||||
# the scripts returns non-zero and this can be reported to the
|
||||
# host.
|
||||
#
|
||||
# 1. Verify the image
|
||||
# 2. Rename the image
|
||||
|
||||
SIGNATURE_FILE=/tmp/bmc.sig
|
||||
STATUS_FILE=/tmp/bmc.verify
|
||||
|
||||
# Store in /run/initramfs because the behaviour of mv changes
|
||||
# depending on whether the file is moving within a tree or not.
|
||||
IMAGE_FILE=/run/initramfs/bmc-image
|
||||
VERIFIED_FILE=/run/initramfs/image-bmc
|
||||
|
||||
# Make sure we run ERR traps when a function returns an error
|
||||
set -e
|
||||
|
||||
# Write out the result of the script to a status file upon exiting
|
||||
# normally or due to an error
|
||||
exit_handler() {
|
||||
local status="$?"
|
||||
if (( status == 0 )); then
|
||||
echo "success" >"${STATUS_FILE}"
|
||||
else
|
||||
echo "failed" >"${STATUS_FILE}"
|
||||
fi
|
||||
trap - EXIT ERR
|
||||
exit "$status"
|
||||
}
|
||||
trap exit_handler EXIT ERR
|
||||
|
||||
echo "running" > ${STATUS_FILE}
|
||||
|
||||
# Verify the image.
|
||||
verify-bmc-image.sh @ALLOW_DEV@ "$IMAGE_FILE" "$SIGNATURE_FILE" || exit
|
||||
|
||||
# Rename the staged file for initramfs updates.
|
||||
mv ${IMAGE_FILE} ${VERIFIED_FILE}
|
||||
@@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=Version string for inplace BMC
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
StandardOutput=file:/run/inplace-gbmc-version
|
||||
StandardError=journal
|
||||
ExecStartPre=/bin/rm -f /run/inplace-gbmc-version
|
||||
ExecStart=/usr/bin/inplace-gbmc-version.sh
|
||||
@@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
# Copyright 2021 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
grep '^VERSION_ID=' /etc/os-release | sed 's,.*-\([^-]*\),\1,g' | tr -d '\n'
|
||||
Reference in New Issue
Block a user