Skip to content

Commit

Permalink
Identifying machines with common CPU modules
Browse files Browse the repository at this point in the history
This patch adds support for machines that use a common CPU module.
These modules provide a common CPU, memory and storage system for
switching platforms. The CPU module can be plugged into a variety of
base boards where the switching elements reside.

The idea is to have a single ONIE "machine" for the CPU module and
detect at run time what the baseboard is.

The platform identification originates from /etc/machine.conf, a
portion of which is now derived at run time.  Along with this a new
configuration variable, "onie_build_machine" is introduced.

/etc/machine.conf
=================

Previously this file was completely built at compile time.  This file
is now a small wrapper script that sources two new files,
/etc/machine-build.conf and /etc/machine-live.conf.

/etc/machine-build.conf -- this file is completely built at compile
time and only contains information known at build time.  This file
introduces a new configuration variable, "onie_build_machine", which
is the ONIE machine specified at compile time.  For example this would
be the ONIE machine name of the common CPU module.

/etc/machine-live.conf -- this file is built at run time.  A boot time
init script sources a platform specific file if it exists, executes
the gen_live_config() function and stores the output in
/etc/machine-live.conf.  By default this function outputs nothing, but
a platform can override it produce a runtime ONIE machine name.

Using this mechanism, a machine can redefine 'onie_machine' and
'onie_switch_asic' at run time.  To do this, a machine defines a small
script in the source tree at
machine/<vendor>/rootconf/sysroot-lib-onie/gen-config-platform, which
include a definition of the gen_live_config() function.

If a machine does not define gen-config-platform,
i.e. /etc/machine-live.conf is empty, then the contents of
'onie_build_machine' is used to set 'onie_machine'.  This is
backwardly compatible with how ONIE worked previously.

Updating ONIE
=============

When ONIE updates itself, it will now check that the running
'onie_build_machine' matches the 'onie_build_machine' of the proposed
update image.  Previously it checked that 'onie_machine' matched
between runtime and the image.

Closes: #570
Signed-off-by: Curt Brune <curt@cumulusnetworks.com>
  • Loading branch information
Curt Brune committed Aug 31, 2017
1 parent e0fe278 commit 3cbcb9e
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 31 deletions.
5 changes: 2 additions & 3 deletions build-config/make/firmware-update.make
Expand Up @@ -12,7 +12,7 @@
#

FIRMWARE_DIR = $(MBUILDDIR)/firmware
FIRMWARE_CONF = $(FIRMWARE_DIR)/machine.conf
FIRMWARE_CONF = $(FIRMWARE_DIR)/machine-build.conf
FIRMWARE_UPDATE_BASE = onie-firmware-$(PLATFORM).bin
FIRMWARE_UPDATE_IMAGE = $(IMAGEDIR)/$(FIRMWARE_UPDATE_BASE)

Expand Down Expand Up @@ -61,8 +61,7 @@ $(FIRMWARE_UPDATE_COMPLETE_STAMP): $(IMAGE_UPDATER_SHARCH) $(MACHINE_FW_INSTALLE
$(Q) rm -f $(FIRMWARE_CONF)
$(Q) echo "onie_version=$(FW_VERSION)" >> $(FIRMWARE_CONF)
$(Q) echo "onie_vendor_id=$(VENDOR_ID)" >> $(FIRMWARE_CONF)
$(Q) echo "onie_platform=$(RUNTIME_ONIE_PLATFORM)" >> $(FIRMWARE_CONF)
$(Q) echo "onie_machine=$(RUNTIME_ONIE_MACHINE)" >> $(FIRMWARE_CONF)
$(Q) echo "onie_build_machine=$(ONIE_BUILD_MACHINE)" >> $(FIRMWARE_CONF)
$(Q) echo "onie_machine_rev=$(MACHINE_REV)" >> $(FIRMWARE_CONF)
$(Q) echo "onie_arch=$(ARCH)" >> $(FIRMWARE_CONF)
$(Q) echo "onie_config_version=$(ONIE_CONFIG_VERSION)" >> $(FIRMWARE_CONF)
Expand Down
23 changes: 10 additions & 13 deletions build-config/make/images.make
Expand Up @@ -38,7 +38,7 @@ IMAGE = $(IMAGE_COMPLETE_STAMP)

LSB_RELEASE_FILE = $(MBUILDDIR)/lsb-release
OS_RELEASE_FILE = $(MBUILDDIR)/os-release
MACHINE_CONF = $(MBUILDDIR)/machine.conf
MACHINE_CONF = $(MBUILDDIR)/machine-build.conf

INSTALLER_DIR = $(abspath ../installer)

Expand Down Expand Up @@ -234,15 +234,13 @@ $(SYSROOT_CHECK_STAMP): $(PACKAGES_INSTALL_STAMPS)
endif
$(Q) touch $@

# Setting RUNTIME_ONIE_PLATFORM and RUNTIME_ONIE_MACHINE on the
# command line allows you "fake" a real machine at runtime. This is
# particularly useful when MACHINE is the kvm_x86_64 virtual machine.
# Using these variables you can make the running virtual machine look
# like a specific real machine. This is useful when developing an
# installer for a particular platform. You can develope the installer
# using the virtual machine.
RUNTIME_ONIE_MACHINE ?= $(MACHINE)
RUNTIME_ONIE_PLATFORM ?= $(ARCH)-$(RUNTIME_ONIE_MACHINE)-r$(MACHINE_REV)
# Setting ONIE_BUILD_MACHINE on the command line allows you "fake" a
# real machine at runtime. This is particularly useful when MACHINE
# is the kvm_x86_64 virtual machine. Using these variables you can
# make the running virtual machine look like a specific real machine.
# This is useful when developing an installer for a particular
# platform. You can develop the installer using the virtual machine.
ONIE_BUILD_MACHINE ?= $(MACHINE)

sysroot-complete: $(SYSROOT_COMPLETE_STAMP)
$(SYSROOT_COMPLETE_STAMP): $(SYSROOT_CHECK_STAMP)
Expand Down Expand Up @@ -282,8 +280,7 @@ $(SYSROOT_COMPLETE_STAMP): $(SYSROOT_CHECK_STAMP)
$(Q) rm -f $(MACHINE_CONF)
$(Q) echo "onie_version=$(LSB_RELEASE_TAG)" >> $(MACHINE_CONF)
$(Q) echo "onie_vendor_id=$(VENDOR_ID)" >> $(MACHINE_CONF)
$(Q) echo "onie_platform=$(RUNTIME_ONIE_PLATFORM)" >> $(MACHINE_CONF)
$(Q) echo "onie_machine=$(RUNTIME_ONIE_MACHINE)" >> $(MACHINE_CONF)
$(Q) echo "onie_build_machine=$(ONIE_BUILD_MACHINE)" >> $(MACHINE_CONF)
$(Q) echo "onie_machine_rev=$(MACHINE_REV)" >> $(MACHINE_CONF)
$(Q) echo "onie_arch=$(ARCH)" >> $(MACHINE_CONF)
$(Q) echo "onie_config_version=$(ONIE_CONFIG_VERSION)" >> $(MACHINE_CONF)
Expand All @@ -298,7 +295,7 @@ $(SYSROOT_COMPLETE_STAMP): $(SYSROOT_CHECK_STAMP)
endif
$(Q) cp $(LSB_RELEASE_FILE) $(SYSROOTDIR)/etc/lsb-release
$(Q) cp $(OS_RELEASE_FILE) $(SYSROOTDIR)/etc/os-release
$(Q) cp $(MACHINE_CONF) $(SYSROOTDIR)/etc/machine.conf
$(Q) cp $(MACHINE_CONF) $(SYSROOTDIR)/etc/machine-build.conf
$(Q) touch $@

# This step creates the cpio archive and compresses it
Expand Down
2 changes: 1 addition & 1 deletion build-config/scripts/onie-mk-installer.sh
Expand Up @@ -206,7 +206,7 @@ EOF
$tmp_installdir/grub.d/50_onie_grub
fi

sed -e 's/onie_/image_/' $machine_conf > $tmp_installdir/machine.conf || exit 1
sed -e 's/onie_/image_/' $machine_conf > $tmp_installdir/machine-build.conf || exit 1
echo -n "."

if [ "$update_type" = "firmware" ] ; then
Expand Down
6 changes: 3 additions & 3 deletions installer/grub-arch/install-arch
Expand Up @@ -15,11 +15,11 @@
. ./installer.conf

# Load machine info from image to be installed.
[ -r ./machine.conf ] || {
echo "ERROR: ONIE update image machine.conf file is missing."
[ -r ./machine-build.conf ] || {
echo "ERROR: ONIE update image machine-build.conf file is missing."
exit 1
}
. ./machine.conf
. ./machine-build.conf

# get running machine from conf file
[ -r /etc/machine.conf ] && . /etc/machine.conf
Expand Down
20 changes: 12 additions & 8 deletions installer/install.sh
Expand Up @@ -7,11 +7,11 @@

cd $(dirname $0)

[ -r ./machine.conf ] || {
echo "ERROR: machine.conf file is missing."
[ -r ./machine-build.conf ] || {
echo "ERROR: machine-build.conf file is missing."
exit 1
}
. ./machine.conf
. ./machine-build.conf

# Default implementation is no additional args
parse_arg_arch()
Expand Down Expand Up @@ -44,6 +44,10 @@ true ${onie_machine_rev=0}
# assume it is 0.
true ${onie_config_version=0}

# for backward compatibility, if running onie_build_machine is empty
# assign the value from onie_machine.
onie_build_machine=${onie_build_machine:-$onie_machine}

args="hivfqx${args_arch}"

usage()
Expand Down Expand Up @@ -99,7 +103,7 @@ while getopts "$args" a ; do
;;
i)
# Dump the image information
cat ./machine.conf
cat ./machine-build.conf
exit 0
;;
*)
Expand All @@ -121,7 +125,7 @@ xz -d -c onie-update.tar.xz | tar -xf -

check_machine_image()
{
if [ "$onie_machine" != "$image_machine" ] ; then
if [ "$onie_build_machine" != "$image_build_machine" ] ; then
fail=yes
fi
if [ "$onie_machine_rev" != "$image_machine_rev" ] ; then
Expand Down Expand Up @@ -156,15 +160,15 @@ check_machine_image

if [ "$fail" = "yes" ] && [ "$force" = "no" ] ; then
echo "ERROR:$update_label: Machine mismatch"
echo "Running machine : ${onie_arch}-${onie_machine}-${onie_machine_rev}"
echo "Update Image machine: ${image_arch}-${image_machine}-${image_machine_rev}"
echo "Running platform : ${onie_arch}-${onie_build_machine}-r${onie_machine_rev}"
echo "Update Image platform: ${image_arch}-${image_build_machine}-r${image_machine_rev}"
echo "Source URL: $onie_exec_url"
exit 1
fi

[ "$quiet" = "no" ] && echo "$update_label: Version : $image_version"
[ "$quiet" = "no" ] && echo "$update_label: Architecture : $image_arch"
[ "$quiet" = "no" ] && echo "$update_label: Machine : $image_machine"
[ "$quiet" = "no" ] && echo "$update_label: Machine : $image_build_machine"
[ "$quiet" = "no" ] && echo "$update_label: Machine Rev : $image_machine_rev"
[ "$quiet" = "no" ] && echo "$update_label: Config Version: $image_config_version"

Expand Down
2 changes: 1 addition & 1 deletion rootconf/default/bin/onie-support
Expand Up @@ -64,7 +64,7 @@ if [ -x /usr/bin/onie-syseeprom ] ; then
onie-syseeprom > $save_dir/onie-syseeprom.txt
fi
onie-sysinfo -a > $save_dir/onie-sysinfo.txt
cp /etc/machine.conf $save_dir/machine.txt
cp /etc/machine*.conf $save_dir
blkid > $save_dir/blkid.txt
fdisk -l > $save_dir/fdisk.txt
support_arch
Expand Down
13 changes: 11 additions & 2 deletions rootconf/default/bin/onie-sysinfo
Expand Up @@ -95,7 +95,7 @@ get_ethaddr()
[ -r $lib_dir/sysinfo-arch ] && . $lib_dir/sysinfo-arch
[ -r $lib_dir/sysinfo-platform ] && . $lib_dir/sysinfo-platform

args="hsSevimrpcfdatP"
args="hsbSevimrpcfdatP"

usage()
{
Expand Down Expand Up @@ -125,6 +125,9 @@ COMMAND LINE OPTIONS
-i
ONIE vendor ID. Print the ONIE vendor's IANA enterprise number.
-b
ONIE build machine string
-m
ONIE machine string
Expand Down Expand Up @@ -158,6 +161,7 @@ sn=no
mac=no
version=no
vendor_id=no
build_machine=no
machine=no
machine_rev=no
platform=no
Expand Down Expand Up @@ -192,6 +196,9 @@ while getopts "$args" a ; do
i)
vendor_id=yes
;;
b)
build_machine=yes
;;
m)
machine=yes
;;
Expand Down Expand Up @@ -255,7 +262,9 @@ if [ "$mac" = "yes" ] || [ "$all" = "yes" ] ; then
print_val $val
fi

for v in version vendor_id machine machine_rev platform arch config_version partition_type build_date switch_asic ; do
for v in version vendor_id build_machine machine \
machine_rev platform arch config_version \
partition_type build_date switch_asic ; do
eval dump='$'$v
if [ "$dump" = "yes" ] || [ "$all" = "yes" ] ; then
eval val='$onie'_$v
Expand Down
26 changes: 26 additions & 0 deletions rootconf/default/etc/init.d/gen-config.sh
@@ -0,0 +1,26 @@
#!/bin/sh

# Copyright (C) 2017 Curt Brune <curt@cumulusnetworks.com>
#
# SPDX-License-Identifier: GPL-2.0

# If necessary, generate run-time ONIE configuration variables in
# /etc/machine-live.conf.

cmd="$1"

gen_live_config()
{
# NO-OP
true
}

[ -r /lib/onie/gen-config-platform ] && . /lib/onie/gen-config-platform

case $cmd in
start)
gen_live_config > /etc/machine-live.conf
;;
*)

esac
16 changes: 16 additions & 0 deletions rootconf/default/etc/machine.conf
@@ -0,0 +1,16 @@
# /etc/machine.conf for onie

# Copyright (C) 2017 Curt Brune <curt@cumulusnetworks.com>
#
# SPDX-License-Identifier: GPL-2.0

# Source build-time machine configuration
. /etc/machine-build.conf

# Source run-time machine configuration if available
[ -r /etc/machine-live.conf ] && . /etc/machine-live.conf

# Use onie_machine if set, otherwise use build_machine
onie_machine=${onie_machine:-$onie_build_machine}

onie_platform="${onie_arch}-${onie_machine}-r${onie_machine_rev}"
1 change: 1 addition & 0 deletions rootconf/default/etc/rcS.d/S05gen-config.sh

0 comments on commit 3cbcb9e

Please sign in to comment.