diff options
Diffstat (limited to 'meta-google')
26 files changed, 498 insertions, 59 deletions
diff --git a/meta-google/recipes-core/busybox/busybox_%.bbappend b/meta-google/recipes-core/busybox/busybox_%.bbappend index 0f2210d7f..fd7873cc1 100644 --- a/meta-google/recipes-core/busybox/busybox_%.bbappend +++ b/meta-google/recipes-core/busybox/busybox_%.bbappend @@ -1,2 +1,3 @@ FILESEXTRAPATHS:prepend:gbmc := "${THISDIR}/files:" SRC_URI:append:gbmc = " file://gbmc.cfg" +SRC_URI:remove:gbmc = "file://syslog.cfg" diff --git a/meta-google/recipes-core/busybox/files/gbmc.cfg b/meta-google/recipes-core/busybox/files/gbmc.cfg index 158f771b3..c76e4f0a7 100644 --- a/meta-google/recipes-core/busybox/files/gbmc.cfg +++ b/meta-google/recipes-core/busybox/files/gbmc.cfg @@ -19,3 +19,37 @@ CONFIG_FEATURE_UDHCPC6_RFC5970=y # Misc CONFIG_BC=y +CONFIG_TRUNCATE=y +CONFIG_BASE64=y +CONFIG_FEATURE_TOP_INTERACTIVE=y +CONFIG_FEATURE_TOP_SMP_CPU=y +CONFIG_FEATURE_TOP_SMP_PROCESS=y +CONFIG_FEATURE_TOPMEM=y + +# Remove unused things +CONFIG_BUNZIP2=n +CONFIG_BZIP2=n +CONFIG_UNZIP=n +CONFIG_ADDGROUP=n +CONFIG_ADDUSER=n +CONFIG_DELGROUP=n +CONFIG_DELUSER=n +CONFIG_LOGIN=n +CONFIG_SU=n +CONFIG_SULOGIN=n +CONFIG_FDISK=n +CONFIG_FSTRIM=n +CONFIG_MKSWAP=n +CONFIG_SWAPON=n +CONFIG_SWAPOFF=n +CONFIG_WATCHDOG=n +CONFIG_IFCONFIG=n +CONFIG_IFUP=n +CONFIG_IFDOWN=n +CONFIG_ROUTE=n +CONFIG_TFTP=n +CONFIG_TLS=n +CONFIG_TRACEROUTE=n +CONFIG_KLOGD=n +CONFIG_LOGREAD=n +CONFIG_SYSLOGD=n diff --git a/meta-google/recipes-core/os-release/os-release.bbappend b/meta-google/recipes-core/os-release/os-release.bbappend index f6b7cc152..635f7c5ae 100644 --- a/meta-google/recipes-core/os-release/os-release.bbappend +++ b/meta-google/recipes-core/os-release/os-release.bbappend @@ -8,4 +8,4 @@ python() { } IMAGE_TYPE = "${GBMC_CONFIG}" -OS_RELEASE_FIELDS:append = " BUILD_MEMO IMAGE_TYPE" +OS_RELEASE_FIELDS:append:gbmc = " BUILD_MEMO IMAGE_TYPE" diff --git a/meta-google/recipes-core/systemd/systemd_%.bbappend b/meta-google/recipes-core/systemd/systemd_%.bbappend index 59751059a..5185a5eaf 100644 --- a/meta-google/recipes-core/systemd/systemd_%.bbappend +++ b/meta-google/recipes-core/systemd/systemd_%.bbappend @@ -6,3 +6,6 @@ PACKAGECONFIG:remove:gbmc = "timesyncd" # We don't need any legacy sysv rc compatability PACKAGECONFIG:remove:gbmc = "sysvinit" + +# We don't enable kernel modules +PACKAGECONFIG:remove:gbmc = "kmod" diff --git a/meta-google/recipes-google/google-misc/google-misc.inc b/meta-google/recipes-google/google-misc/google-misc.inc index 49535873b..cd2c37975 100644 --- a/meta-google/recipes-google/google-misc/google-misc.inc +++ b/meta-google/recipes-google/google-misc/google-misc.inc @@ -6,7 +6,7 @@ LICENSE = "Apache-2.0" LIC_FILES_CHKSUM = "file://../../LICENSE;md5=34400b68072d710fecd0a2940a0d1658" SRC_URI += "git://github.com/openbmc/google-misc" -SRCREV = "379b061ffdd797d00c07acf0b5cb81e1f6513bca" +SRCREV = "ddf93d57c15ad453ba1498ab8553302c0361dfbe" S = "${WORKDIR}/git/subprojects/${GOOGLE_MISC_PROJ}" inherit meson diff --git a/meta-google/recipes-google/ncsi/files/25-gbmc-ncsi-clear-ip.sh.in b/meta-google/recipes-google/ncsi/files/25-gbmc-ncsi-clear-ip.sh.in new file mode 100644 index 000000000..e17a5e200 --- /dev/null +++ b/meta-google/recipes-google/ncsi/files/25-gbmc-ncsi-clear-ip.sh.in @@ -0,0 +1,26 @@ +# 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_ncsi_clear_ip-}" ] || exit + +source /usr/libexec/ncsid_lib.sh || exit + +gbmc_ncsi_clear_ip_hook() { + UpdateIP xyz.openbmc_project.Network '@NCSI_IF@' '0.0.0.0' '0' || true + UpdateIP xyz.openbmc_project.Network '@NCSI_IF@' '::' '0' || true +} + +GBMC_BR_DHCP_HOOKS+=(gbmc_ncsi_clear_ip_hook) + +gbmc_ncsi_clear_ip=1 diff --git a/meta-google/recipes-google/ncsi/files/gbmc-ncsi-br-deprecated-ips.sh.in b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-br-deprecated-ips.sh.in new file mode 100644 index 000000000..9d9f7899e --- /dev/null +++ b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-br-deprecated-ips.sh.in @@ -0,0 +1,130 @@ +# 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_ncsi_br_deprecated_ips_lib-}" ] || return + +source /usr/share/network/lib.sh || exit + +gbmc_ncsi_br_deprecated_ips_init= +gbmc_ncsi_br_deprecated_ips_confip= +gbmc_ncsi_br_deprecated_ips_lastip= + +gbmc_ncsi_br_deprecated_ips_update() { + [ -n "$gbmc_ncsi_br_deprecated_ips_init" ] || return + [ "$gbmc_ncsi_br_deprecated_ips_confip" != "$gbmc_ncsi_br_deprecated_ips_lastip" ] || return + gbmc_ncsi_br_deprecated_ips_confip="$gbmc_ncsi_br_deprecated_ips_lastip" + + printf 'gBMC Bridge NCSI Deprecated Addrs: %s\n' \ + "${gbmc_ncsi_br_deprecated_ips_lastip:-(deleted)}" >&2 + + local contents= + local nfcontents= + if [ -n "$gbmc_ncsi_br_deprecated_ips_lastip" ]; then + local pfx_bytes=() + ip_to_bytes pfx_bytes "$gbmc_ncsi_br_deprecated_ips_lastip" + + local pfx="$(ip_bytes_to_str pfx_bytes)" + (( pfx_bytes[9] &= 0xf0 )) + local stateless_pfx="$(ip_bytes_to_str pfx_bytes)" + pfx_bytes[8]=0 + pfx_bytes[9]=0 + local host_pfx="$(ip_bytes_to_str pfx_bytes)" + read -r -d '' contents <<EOF +[Address] +Address=$pfx/128 +PreferredLifetime=0 +[Address] +Address=$stateless_pfx/128 +PreferredLifetime=0 +[Address] +Address=$host_pfx/128 +PreferredLifetime=0 +EOF + read -r -d '' nfcontents <<EOF +table inet filter { + chain ncsi_input { + ip6 saddr != $pfx/76 ip6 daddr $pfx/76 goto ncsi_gbmc_br_pub_input + } + chain ncsi_forward { + ip6 saddr != $pfx/76 ip6 daddr $pfx/76 accept + } +} +EOF + fi + + local file + for file in /run/systemd/network/{00,}-bmc-@NCSI_IF@.network.d/50-deprecated.conf; do + mkdir -p -m 755 "$(dirname "$file")" + if [ -z "$contents" ]; then + rm -f "$file" + else + printf '%s' "$contents" >"$file" + fi + done + + # Ensure that systemd-networkd performs a reconfiguration as it doesn't + # currently check the mtime of drop-in files. + touch -c /etc/systemd/network/*-bmc-@NCSI_IF@.network + + if [ "$(systemctl is-active systemd-networkd)" != 'inactive' ]; then + networkctl reload && networkctl reconfigure @NCSI_IF@ + fi + + local rfile=/run/nftables/40-gbmc-ncsi-br.rules + mkdir -p -m 755 "$(dirname "$rfile")" + if [ -z "$nfcontents" ]; then + rm -f "$rfile" + else + printf '%s' "$nfcontents" >"$rfile" + fi + systemctl reset-failed nftables && systemctl --no-block reload-or-restart nftables || true +} + +gbmc_ncsi_br_deprecated_ips_hook() { + if [ "$change" = 'init' ]; then + gbmc_ncsi_br_deprecated_ips_init=1 + gbmc_ip_monitor_defer + elif [ "$change" = 'defer' ]; then + gbmc_ncsi_br_deprecated_ips_update + elif [ "$change" = 'addr' -a "$intf" = 'gbmcbr' ] && + [ "$scope" = 'global' -a "$fam" = 'inet6' ]; then + local pfx_bytes=() + ip_to_bytes pfx_bytes "$ip" || return + # No ULA Addresses + if (( pfx_bytes[0] & 0xfe == 0xfc )); then + return + fi + # We only want to allow a <pfx>::fd0x address, where x>0 + if (( pfx_bytes[8] != 0xfd || pfx_bytes[9] & 0xf == 0 )); then + return + fi + for (( i = 10; i < 16; ++i )); do + if (( pfx_bytes[i] != 0 )); then + return + fi + done + if [ "$action" = 'add' -a "$ip" != "$gbmc_ncsi_br_deprecated_ips_lastip" ]; then + gbmc_ncsi_br_deprecated_ips_lastip="$ip" + gbmc_ip_monitor_defer + fi + if [ "$action" = 'del' -a "$ip" = "$gbmc_ncsi_br_deprecated_ips_lastip" ]; then + gbmc_ncsi_br_deprecated_ips_lastip= + gbmc_ip_monitor_defer + fi + fi +} + +GBMC_IP_MONITOR_HOOKS+=(gbmc_ncsi_br_deprecated_ips_hook) + +gbmc_ncsi_br_deprecated_ips_lib=1 diff --git a/meta-google/recipes-google/ncsi/files/gbmc-ncsi-br-pub-addr.sh.in b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-br-pub-addr.sh.in index 5adc41328..793403348 100644 --- a/meta-google/recipes-google/ncsi/files/gbmc-ncsi-br-pub-addr.sh.in +++ b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-br-pub-addr.sh.in @@ -63,6 +63,8 @@ Destination=$stateless_pfx/76 Type=unreachable Metric=1024 EOF + # Delete DHCP configured addresses if we have a host published address + rm -f /etc/systemd/network/{00,}-bmc-gbmcbr.network.d/50-public.conf fi local file diff --git a/meta-google/recipes-google/ncsi/files/gbmc-ncsi-ip-from-ra.sh.in b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-ip-from-ra.sh.in index 80bd34f04..2788f7f19 100755 --- a/meta-google/recipes-google/ncsi/files/gbmc-ncsi-ip-from-ra.sh.in +++ b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-ip-from-ra.sh.in @@ -41,6 +41,9 @@ set_net() { echo "Found prefix $pfx from $rtr" >&2 + # We no longer need NCSId if we are in this configuration + systemctl stop --no-block ncsid@"$NCSI_IF" || true + # Delete any stale IP Addresses from the primary interface as we won't use them UpdateIP xyz.openbmc_project.Network "$NCSI_IF" '0.0.0.0' '0' || true UpdateIP xyz.openbmc_project.Network "$NCSI_IF" '::' '0' || true @@ -70,7 +73,6 @@ EOF touch -c /lib/systemd/network/*-bmc-gbmcbr.network || true contents='[Network]'$'\n' - contents+="Address=$pfx/128"$'\n' contents+="Gateway=$rtr"$'\n' for file in /run/systemd/network/{00,}-bmc-"$NCSI_IF".network.d/49-public-ra.conf; do mkdir -p -m 755 "$(dirname "$file")" @@ -81,21 +83,6 @@ EOF if [ "$(systemctl is-active systemd-networkd)" != 'inactive' ]; then networkctl reload && networkctl reconfigure gbmcbr "$NCSI_IF" || true fi - - read -r -d '' contents <<EOF -table inet filter { - chain ncsi_input { - ip6 saddr != $pfx/76 ip6 daddr $pfx/76 goto ncsi_gbmc_br_pub_input - } - chain ncsi_forward { - ip6 saddr != $pfx/76 ip6 daddr $pfx/76 accept - } -} -EOF - rfile=/run/nftables/40-gbmc-ncsi-ra.rules - mkdir -p -m 755 "$(dirname "$rfile")" - printf '%s' "$contents" >"$rfile" - systemctl reset-failed nftables && systemctl --no-block restart nftables || true } w=60 diff --git a/meta-google/recipes-google/ncsi/files/gbmc-ncsi-nft.sh.in b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-nft.sh.in index 7a630f5fe..074ec5785 100644 --- a/meta-google/recipes-google/ncsi/files/gbmc-ncsi-nft.sh.in +++ b/meta-google/recipes-google/ncsi/files/gbmc-ncsi-nft.sh.in @@ -35,45 +35,18 @@ gbmc_ncsi_nft_update() { fi local ip6="$gbmc_ncsi_nft_lastip6" - local pfx= if [ -n "$ip6" ]; then contents+=" ip6 daddr $ip6/128 goto ncsi_legacy_input"$'\n' - - local ip_bytes=() - ip_to_bytes ip_bytes "$ip6" - # If our address has enough spare bits for appending the BMC suffix - # then we add a rule that allows the BMC subnet. That is, we need a /64 - # as input. - local i - for (( i = 8; i < 16; i++ )); do - if (( ip_bytes[$i] != 0 )); then - ip_bytes=() - break - fi - done - if (( ${#ip_bytes[@]} != 0 )); then - ip_bytes[8]=0xfd - pfx="$(ip_bytes_to_str ip_bytes)" - contents+=" ip6 saddr != $pfx/76 ip6 daddr" - contents+=" $pfx/76 goto ncsi_gbmc_br_pub_input"$'\n' - fi fi contents+=' }'$'\n' - contents+=' chain ncsi_forward {'$'\n' - if [ -n "$pfx" ]; then - contents+=" ip6 saddr != $pfx/76 ip6 daddr $pfx/76 accept"$'\n' - fi - contents+=' }'$'\n' contents+='}'$'\n' local rfile=/run/nftables/40-gbmc-ncsi-in.rules mkdir -p -m 755 "$(dirname "$rfile")" printf '%s' "$contents" >"$rfile" - echo 'Restarting nftables' >&2 - systemctl reset-failed nftables - systemctl --no-block restart nftables + systemctl reset-failed nftables && systemctl --no-block reload-or-restart nftables || true } gbmc_ncsi_nft_hook() { diff --git a/meta-google/recipes-google/ncsi/gbmc-ncsi-config.bb b/meta-google/recipes-google/ncsi/gbmc-ncsi-config.bb index 10ef56a76..0312f0502 100644 --- a/meta-google/recipes-google/ncsi/gbmc-ncsi-config.bb +++ b/meta-google/recipes-google/ncsi/gbmc-ncsi-config.bb @@ -18,7 +18,9 @@ SRC_URI += " \ file://gbmc-ncsi-sslh.service \ file://gbmc-ncsi-nft.sh.in \ file://gbmc-ncsi-br-pub-addr.sh.in \ + file://gbmc-ncsi-br-deprecated-ips.sh.in \ file://gbmc-ncsi-set-nicenabled.service.in \ + file://25-gbmc-ncsi-clear-ip.sh.in \ " S = "${WORKDIR}" @@ -35,6 +37,7 @@ RDEPENDS:${PN} += " \ " FILES:${PN} += " \ + ${datadir}/gbmc-br-dhcp \ ${datadir}/gbmc-ip-monitor \ ${systemd_unitdir} \ " @@ -100,6 +103,15 @@ do_install:append() { sed "s,@NCSI_IF@,$if_name,g" ${WORKDIR}/gbmc-ncsi-br-pub-addr.sh.in \ >${WORKDIR}/gbmc-ncsi-br-pub-addr.sh install -m644 ${WORKDIR}/gbmc-ncsi-br-pub-addr.sh $mondir + sed "s,@NCSI_IF@,$if_name,g" ${WORKDIR}/gbmc-ncsi-br-deprecated-ips.sh.in \ + >${WORKDIR}/gbmc-ncsi-br-deprecated-ips.sh + install -m644 ${WORKDIR}/gbmc-ncsi-br-deprecated-ips.sh $mondir + + dhcpdir=${D}${datadir}/gbmc-br-dhcp/ + install -d -m0755 $dhcpdir + sed "s,@NCSI_IF@,$if_name,g" ${WORKDIR}/25-gbmc-ncsi-clear-ip.sh.in \ + >${WORKDIR}/25-gbmc-ncsi-clear-ip.sh + install -m644 ${WORKDIR}/25-gbmc-ncsi-clear-ip.sh $dhcpdir sed "s,@NCSI_IF@,$if_name,g" ${WORKDIR}/gbmc-ncsi-set-nicenabled.service.in \ >${D}${systemd_system_unitdir}/gbmc-ncsi-set-nicenabled.service diff --git a/meta-google/recipes-google/networking/gbmc-bridge.bb b/meta-google/recipes-google/networking/gbmc-bridge.bb index dea14f00b..509d871d9 100644 --- a/meta-google/recipes-google/networking/gbmc-bridge.bb +++ b/meta-google/recipes-google/networking/gbmc-bridge.bb @@ -20,6 +20,8 @@ SRC_URI += " \ file://gbmc-br-ensure-ra.service \ file://gbmc-br-gw-src.sh \ file://gbmc-br-nft.sh \ + file://gbmc-br-dhcp.sh \ + file://gbmc-br-dhcp.service \ " FILES:${PN}:append = " \ @@ -37,7 +39,10 @@ RDEPENDS:${PN}:append = " \ ndisc6-rdisc6 \ " -SYSTEMD_SERVICE:${PN} += "gbmc-br-ensure-ra.service" +SYSTEMD_SERVICE:${PN} += " \ + gbmc-br-ensure-ra.service \ + gbmc-br-dhcp.service \ + " GBMC_BR_MAC_ADDR ?= "" @@ -94,8 +99,10 @@ do_install() { install -d -m0755 ${D}${libexecdir} install -m0755 ${WORKDIR}/gbmc-br-ensure-ra.sh ${D}${libexecdir}/ + install -m0755 ${WORKDIR}/gbmc-br-dhcp.sh ${D}${libexecdir}/ install -d -m0755 ${D}${systemd_system_unitdir} - install -m0755 ${WORKDIR}/gbmc-br-ensure-ra.service ${D}${systemd_system_unitdir}/ + install -m0644 ${WORKDIR}/gbmc-br-ensure-ra.service ${D}${systemd_system_unitdir}/ + install -m0644 ${WORKDIR}/gbmc-br-dhcp.service ${D}${systemd_system_unitdir}/ } do_rm_work:prepend() { diff --git a/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-dhcp.service b/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-dhcp.service new file mode 100644 index 000000000..7eb0ce075 --- /dev/null +++ b/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-dhcp.service @@ -0,0 +1,13 @@ +[Unit] +Description=gBMC DHCP Client +After=network.target +StartLimitIntervalSec=10 +StartLimitBurst=3 + +[Service] +Restart=always +RestartSec=5 +ExecStart=/usr/bin/udhcpc6 -f -q -O fqdn -O bootfile_url -O bootfile_param -i gbmcbr -s /usr/libexec/gbmc-br-dhcp.sh + +[Install] +WantedBy=multi-user.target diff --git a/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-dhcp.sh b/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-dhcp.sh new file mode 100644 index 000000000..42a077d09 --- /dev/null +++ b/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-dhcp.sh @@ -0,0 +1,101 @@ +#!/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. + +# A list of functions which get executed for each bound DHCP lease. +# These are configured by the files included below. +GBMC_BR_DHCP_HOOKS=() + +# Load configurations from a known location in the filesystem to populate +# hooks that are executed after each event. +shopt -s nullglob +for conf in /usr/share/gbmc-br-dhcp/*.sh; do + # SC doesn't like dynamic source loading + # shellcheck disable=SC1090 + source "$conf" +done + +gbmc_br_dhcp_run_hooks() { + local hook + for hook in "${GBMC_BR_DHCP_HOOKS[@]}"; do + "$hook" || continue + done +} + +# SC can't find this path during repotest +# shellcheck disable=SC1091 +source /usr/share/network/lib.sh || exit + +if [ "$1" = bound ]; then + # Variable is from the environment via udhcpc6 + # shellcheck disable=SC2154 + echo "DHCPv6(gbmcbr): $ipv6/128" >&2 + + pfx_bytes=() + ip_to_bytes pfx_bytes "$ipv6" + # Ensure we are a BMC and have a suffix nibble, the 0th index is reserved + if (( pfx_bytes[8] != 0xfd || pfx_bytes[9] & 0xf == 0 )); then + echo "Invalid address" >&2 + exit + fi + # Ensure we don't have more than a /80 address + for (( i = 10; i < 16; ++i )); do + if (( pfx_bytes[i] != 0 )); then + echo "Invalid address" >&2 + exit + fi + done + + pfx="$(ip_bytes_to_str pfx_bytes)" + (( pfx_bytes[9] &= 0xf0 )) + stateless_pfx="$(ip_bytes_to_str pfx_bytes)" + read -r -d '' contents <<EOF +[Network] +Address=$pfx/128 +IPv6PrefixDelegation=yes +[IPv6PrefixDelegation] +RouterLifetimeSec=60 +[IPv6Prefix] +Prefix=$stateless_pfx/80 +PreferredLifetimeSec=60 +ValidLifetimeSec=60 +[IPv6RoutePrefix] +Route=$pfx/80 +LifetimeSec=60 +[Route] +Destination=$stateless_pfx/76 +Type=unreachable +Metric=1024 +EOF + + for file in /etc/systemd/network/{00,}-bmc-gbmcbr.network.d/50-public.conf; do + mkdir -p "$(dirname "$file")" + printf '%s' "$contents" >"$file" + done + + # Ensure that systemd-networkd performs a reconfiguration as it doesn't + # currently check the mtime of drop-in files. + touch -c /lib/systemd/network/*-bmc-gbmcbr.network + + if [ "$(systemctl is-active systemd-networkd)" != 'inactive' ]; then + networkctl reload && networkctl reconfigure gbmcbr + fi + + if [ -n "${fqdn-}" ]; then + echo "Using hostname $fqdn" >&2 + hostnamectl set-hostname "$fqdn" || true + fi + + gbmc_br_dhcp_run_hooks +fi diff --git a/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-nft.sh b/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-nft.sh index 980f7b6d6..ca4e15a1f 100644 --- a/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-nft.sh +++ b/meta-google/recipes-google/networking/gbmc-bridge/gbmc-br-nft.sh @@ -37,9 +37,7 @@ gbmc_br_nft_update() { mkdir -p -m 755 "$(dirname "$rfile")" printf '%s' "$contents" >"$rfile" - echo 'Restarting nftables' >&2 - systemctl reset-failed nftables - systemctl --no-block restart nftables + systemctl reset-failed nftables && systemctl --no-block reload-or-restart nftables || true } gbmc_br_nft_hook() { diff --git a/meta-google/recipes-google/nftables/files/nft-configure.sh b/meta-google/recipes-google/nftables/files/nft-configure.sh index 05bb23d8b..8c8e058b7 100644 --- a/meta-google/recipes-google/nftables/files/nft-configure.sh +++ b/meta-google/recipes-google/nftables/files/nft-configure.sh @@ -8,10 +8,14 @@ for dir in /run/nftables /etc/nftables /usr/share/nftables; do done let i+=1 done -rc=0 -nft flush ruleset || rc=$? + +rules="" +trap 'rm -f -- "$rules"' TERM INT EXIT ERR +rules="$(mktemp)" || exit +echo 'flush ruleset' >"$rules" for key in $(printf "%s\n" "${!basemap[@]}" | sort -r); do - echo "Executing ${basemap[$key]}" >&2 - nft -f "${basemap[$key]}" || rc=$? + echo "Loading ${basemap[$key]}" >&2 + echo '' >>"$rules" + cat "${basemap[$key]}" >>"$rules" done -exit $rc +nft -f "$rules" || exit diff --git a/meta-google/recipes-google/nftables/files/nftables.service b/meta-google/recipes-google/nftables/files/nftables.service index 770a3d3ac..1a93812b8 100644 --- a/meta-google/recipes-google/nftables/files/nftables.service +++ b/meta-google/recipes-google/nftables/files/nftables.service @@ -5,6 +5,7 @@ Before=network-pre.target Type=oneshot RemainAfterExit=yes ExecStart=/usr/libexec/nft-configure.sh +ExecReload=/usr/libexec/nft-configure.sh ExecStop=/usr/sbin/nft flush ruleset [Install] diff --git a/meta-google/recipes-google/systemd/files/40-system.conf b/meta-google/recipes-google/systemd/files/40-system.conf new file mode 100644 index 000000000..5f770d01f --- /dev/null +++ b/meta-google/recipes-google/systemd/files/40-system.conf @@ -0,0 +1,4 @@ +[Manager] +DefaultMemoryAccounting=yes +RuntimeWatchdogSec=10s +WatchdogDevice=/dev/watchdog diff --git a/meta-google/recipes-google/systemd/gbmc-systemd-config.bb b/meta-google/recipes-google/systemd/gbmc-systemd-config.bb index 6e26fc99d..843053bc8 100644 --- a/meta-google/recipes-google/systemd/gbmc-systemd-config.bb +++ b/meta-google/recipes-google/systemd/gbmc-systemd-config.bb @@ -11,11 +11,13 @@ SRC_URI:append = " \ file://firmware-updates.target \ file://firmware-updates-pre.target \ file://40-gbmc-forward.conf \ + file://40-system.conf \ " FILES:${PN}:append = " \ ${systemd_unitdir}/coredump.conf.d/40-gbmc-coredump.conf \ ${systemd_unitdir}/resolved.conf.d/40-gbmc-nomdns.conf \ + ${systemd_unitdir}/system.conf.d/40-system.conf \ ${libdir}/sysctl.d/40-gbmc-forward.conf \ " @@ -44,6 +46,9 @@ do_install() { install -d -m0755 ${D}${libdir}/sysctl.d install -m 0644 ${WORKDIR}/40-gbmc-forward.conf ${D}${libdir}/sysctl.d/ + + install -d -m 0755 ${D}${systemd_unitdir}/system.conf.d/ + install -D -m0644 ${WORKDIR}/40-system.conf ${D}${systemd_unitdir}/system.conf.d/ } do_install:append:dev() { diff --git a/meta-google/recipes-phosphor/flash/gbmc-update.bb b/meta-google/recipes-phosphor/flash/gbmc-update.bb new file mode 100644 index 000000000..2c0f51066 --- /dev/null +++ b/meta-google/recipes-phosphor/flash/gbmc-update.bb @@ -0,0 +1,17 @@ +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://75-gbmc-upgrade.sh \ +" + +FILES:${PN} += "${datadir}/gbmc-br-dhcp" + +do_install() { + install -d ${D}${datadir}/gbmc-br-dhcp + install -m 0644 ${WORKDIR}/75-gbmc-upgrade.sh ${D}${datadir}/gbmc-br-dhcp/ +} diff --git a/meta-google/recipes-phosphor/flash/gbmc-update/75-gbmc-upgrade.sh b/meta-google/recipes-phosphor/flash/gbmc-update/75-gbmc-upgrade.sh new file mode 100644 index 000000000..c94bf5bd0 --- /dev/null +++ b/meta-google/recipes-phosphor/flash/gbmc-update/75-gbmc-upgrade.sh @@ -0,0 +1,66 @@ +#!/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_hook() { + [ -n "${bootfile_url-}" ] || return + + local tmpdir + tmpdir="$(mktemp -d)" || return + gbmc_upgrade_internal || true + # SC doesn't know our variable is defined elsewhere + # shellcheck disable=SC2153 + rm -rf -- "$tmpdir" "$GBMC_UPGRADE_SIG" "$GBMC_UPGRADE_IMG" +} + +gbmc_upgrade_fetch() ( + echo "Fetching $bootfile_url" >&2 + + # We only support tarballs at the moment + if [[ "$bootfile_url" != *.tar ]]; then + 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 + ulimit -H -f $((96 * 1024 * 1024)) || return + wget "$bootfile_url" | tar -xC "$tmpdir" || true + + local sig + sig="$(find "$tmpdir" -name 'image-*.sig')" || 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 + fi + + # Staging packages have a directory named after the version + local vdir="${imgdir##*/}" + if [[ "$vdir" =~ ([0-9]+[.]){3}[0-9]+ ]]; then + echo "$vdir" + fi +) + +GBMC_BR_DHCP_HOOKS+=(gbmc_upgrade_hook) + +gbmc_upgrade=1 diff --git a/meta-google/recipes-phosphor/flash/inplace-gbmc-update.bb b/meta-google/recipes-phosphor/flash/inplace-gbmc-update.bb index 9e55afce5..418ee3932 100644 --- a/meta-google/recipes-phosphor/flash/inplace-gbmc-update.bb +++ b/meta-google/recipes-phosphor/flash/inplace-gbmc-update.bb @@ -10,8 +10,11 @@ inherit obmc-phosphor-systemd PROVIDES += "virtual/bmc-update" RPROVIDES:${PN} += "virtual/bmc-update" -RDEPENDS:${PN} += "google-key" -RDEPENDS:${PN} += "bash" +RDEPENDS:${PN} += " \ + bash \ + gbmc-update \ + google-key \ + " SRC_URI += " \ file://config-bmc.json \ @@ -19,12 +22,14 @@ SRC_URI += " \ file://inplace-gbmc-verify.sh \ file://inplace-gbmc-version.service \ file://inplace-gbmc-version.sh \ + file://75-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 @@ -37,6 +42,9 @@ do_install() { 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}/75-inplace-gbmc-upgrade.sh ${D}${datadir}/gbmc-br-dhcp/ } do_install:prepend:dev() { diff --git a/meta-google/recipes-phosphor/flash/inplace-gbmc-update/75-inplace-gbmc-upgrade.sh b/meta-google/recipes-phosphor/flash/inplace-gbmc-update/75-inplace-gbmc-upgrade.sh new file mode 100644 index 000000000..df4662f6d --- /dev/null +++ b/meta-google/recipes-phosphor/flash/inplace-gbmc-update/75-inplace-gbmc-upgrade.sh @@ -0,0 +1,41 @@ +#!/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 +} + +inplace_gbmc_upgrade=1 diff --git a/meta-google/recipes-phosphor/images/obmc-phosphor-image.bbappend b/meta-google/recipes-phosphor/images/obmc-phosphor-image.bbappend index dce86826f..db3a2575c 100644 --- a/meta-google/recipes-phosphor/images/obmc-phosphor-image.bbappend +++ b/meta-google/recipes-phosphor/images/obmc-phosphor-image.bbappend @@ -17,7 +17,6 @@ OBMC_IMAGE_EXTRA_INSTALL:append:gbmc = \ # Include these useful utilities for all gbmc platforms OBMC_IMAGE_EXTRA_INSTALL:append:gbmc = " ipmitool" -OBMC_IMAGE_EXTRA_INSTALL:append:gbmc = " iotools" OBMC_IMAGE_EXTRA_INSTALL:append:gbmc = " lrzsz" # Add gBMC update recipes diff --git a/meta-google/recipes-phosphor/ipmi/phosphor-ipmi-host_%.bbappend b/meta-google/recipes-phosphor/ipmi/phosphor-ipmi-host_%.bbappend new file mode 100644 index 000000000..77fcbe079 --- /dev/null +++ b/meta-google/recipes-phosphor/ipmi/phosphor-ipmi-host_%.bbappend @@ -0,0 +1,3 @@ +# Neither of these are used in a gbmc configuration +RDEPENDS:${PN}:remove:gbmc = "clear-once" +RDEPENDS:${PN}:remove:gbmc = "${VIRTUAL-RUNTIME_obmc-bmc-updater}" diff --git a/meta-google/recipes-phosphor/sensors/phosphor-hwmon_%.bbappend b/meta-google/recipes-phosphor/sensors/phosphor-hwmon_%.bbappend new file mode 100644 index 000000000..8987adf3d --- /dev/null +++ b/meta-google/recipes-phosphor/sensors/phosphor-hwmon_%.bbappend @@ -0,0 +1,4 @@ +EXTRA_OEMESON:append:gbmc = " \ + -Dupdate-functional-on-fail=true \ + -Dnegative-errno-on-fail=false \ +" |