Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x86: Add an onie-tool command to show ONIE version information #227

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions build-config/make/images.make
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ UPDATER_ONIE_TOOLS = $(MBUILDDIR)/onie-tools.tar.xz

UPDATER_IMAGE = $(IMAGEDIR)/onie-updater-$(ARCH)-$(MACHINE_PREFIX)

ONIE_TOOLS_LIST = \
ONIE_TOOLS_DIR = $(abspath ../tools)
ONIE_SYSROOT_TOOLS_LIST = \
lib/onie \
bin/onie-boot-mode

Expand Down Expand Up @@ -251,9 +252,20 @@ $(SYSROOT_CPIO_XZ) : $(SYSROOT_COMPLETE_STAMP)
$(UPDATER_INITRD) : $(SYSROOT_CPIO_XZ)
ln -sf $< $@

$(UPDATER_ONIE_TOOLS): $(SYSROOT_COMPLETE_STAMP)
ifndef MAKE_CLEAN
ONIE_TOOLS_FILES = $(shell \
test -d $(ONIE_TOOLS_DIR) && test -r $(UPDATER_ONIE_TOOLS) && \
find -L $(ONIE_TOOLS_DIR) -mindepth 1 -cnewer $(UPDATER_ONIE_TOOLS) \
-print -quit 2>/dev/null)
ifneq ($(strip $(ONIE_TOOLS_FILES)),)
$(shell rm -f $(UPDATER_ONIE_TOOLS))
endif
endif

$(UPDATER_ONIE_TOOLS): $(SYSROOT_COMPLETE_STAMP) $(SCRIPTDIR)/onie-mk-tools.sh
$(Q) echo "==== Create ONIE Tools tarball ===="
$(Q) tar -C $(SYSROOTDIR) -cJf $@ $(ONIE_TOOLS_LIST)
$(Q) $(SCRIPTDIR)/onie-mk-tools.sh $(ONIE_ARCH) $(ONIE_TOOLS_DIR) $@ \
$(SYSROOTDIR) $(ONIE_SYSROOT_TOOLS_LIST)

.SECONDARY: $(ITB_IMAGE)

Expand Down
81 changes: 81 additions & 0 deletions build-config/scripts/onie-mk-tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/sh

# Copyright (C) 2015 Curt Brune <[email protected]>
#
# SPDX-License-Identifier: GPL-2.0

#
# Script to create a tarball of "ONIE tools", which are made available
# to the NOS.
#

arch=$1
tools_dir=$2
output_file=$3
sysroot=$4

shift 4

# The tools originate from two locations:
#
# 1. Some CPU architecture independent tools are from the $sysroot of
# the ONIE installer image directly. These tools are unmodified
# copies of what is in the ONIE runtime image.
#
# 2. CPU dependent tools are from an architecture specific directory
# located within the ONIE repo $tools_dir. These tools are *not*
# present in the ONIE runtime image.

[ -d "${tools_dir}/${arch}" ] || {
echo "ERROR: arch tools directory '${tools_dir}/${arch}' does not exist."
exit 1
}

touch $output_file || {
echo "ERROR: unable to create output file: $output_file"
exit 1
}
rm -f $output_file

[ -d "$sysroot" ] || {
echo "ERROR: sysroot directory '$sysroot' does not exist."
exit 1
}

[ $# -gt 0 ] || {
echo "Error: No ONIE sysroot tool files found"
exit 1
}

tmp_dir=
clean_up()
{
rm -rf $tmp_dir
}

trap clean_up EXIT

# make the tools tarball
# contents:
# - /bin -- shell scripts
# - /lib -- shell script fragments

echo -n "Building ONIE tools archive ."
tmp_dir=$(mktemp --directory)
cp -a "${tools_dir}/${arch}"/* $tmp_dir
echo -n "."
for f in $* ; do
tdir="${tmp_dir}/$(dirname $f)"
mkdir -p $tdir || exit 1
cp -a "${sysroot}/$f" $tdir || exit 1
echo -n "."
done

# Bundle data into a tar file
tar -C $tmp_dir -cJf $output_file $(ls $tmp_dir) || exit 1
echo -n "."

rm -rf $tmp_dir
echo " Done."

echo "Success: ONIE tools tar archive is ready: ${output_file}"
23 changes: 23 additions & 0 deletions tools/x86_64/bin/onie-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

# Copyright (C) 2015 Curt Brune <[email protected]>
#
# SPDX-License-Identifier: GPL-2.0

# This script is part of the onie-tools package, intended for use by a
# NOS to display information about the ONIE environment. The script
# leverages the ONIE build information from the grub-machine.cfg file.

grub_dir="$(dirname $(realpath $0))/../../grub"

grub_machine_cfg="${grub_dir}/grub-machine.cfg"

if [ -r "$grub_machine_cfg" ] ; then
. "$grub_machine_cfg"
grep = $grub_machine_cfg | sed -e 's/onie_//' -e 's/=.*$//' | while read var ; do
eval val='$'onie_$var
printf "%-20s: %s\n" "ONIE ${var}" "$val"
done
else
echo "Warning: ONIE version information not available" > /dev/stderr
fi