forked from Mellanox/bfscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bfver
executable file
·212 lines (180 loc) · 6.91 KB
/
bfver
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/bin/sh -e
# Copyright (c) 2017, Mellanox Technologies
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and documentation are those
# of the authors and should not be interpreted as representing official policies,
# either expressed or implied, of the FreeBSD Project.
PROGNAME=$(basename "$0")
TMP_DIR=$(mktemp -d)
trap "rm -rf $TMP_DIR" EXIT
trap "rm -rf $TMP_DIR; exit 1" TERM INT
# Build number to use in case it can't be retrieved from BFB.
DEFAULT_BUILD_ID=999
usage ()
{
cat <<EOF
Usage: $PROGNAME [--help|-h]
$PROGNAME [--part|-p PARTITIONS]
$PROGNAME [--file|-f FILE]
Prints version information for currently installed software.
Options:
--help,-h print this message
--part,-p PARTITIONS print version information for all boot partitions
specified in a comma-delimited list. For example,
"-p0,1" will print bootloader versions for
partition 0, and then partition 1. "-p1" will
print only partition 1. If -p is not specified,
the current primary partition will be printed.
--file,-f FILE print BSP version information from a BFB file instead
of what is installed.
EOF
}
print_path_vers () {
# Print the versions of an image at a given path.
# For any file, the versions contained in the BFB will be printed.
# For /dev/mmcblk0boot*, mlxbf-bootctl will be employed to read the
# partition.
STREAM_PATH="$1"
case $STREAM_PATH in
/dev/mmcblk0boot*) print_bfb_installed_vers "$STREAM_PATH";;
*)
if ! [ -e $STREAM_PATH ]; then
echo "$PROGNAME: warn: $STREAM_PATH does not exist, skipping" >&2
elif ! [ -f $STREAM_PATH ]; then
echo "$PROGNAME: warn: $STREAM_PATH is not file, skipping" >&2
else
print_bfb_file_vers "$STREAM_PATH"
fi
;;
esac
}
print_bfb_installed_vers () {
DEV_PATH=$1
CURRENT_BFB="$TMP_DIR/$(basename $DEV_PATH).bfb"
# Retrieve default.bfb from the eMMC
mlxbf-bootctl -r "$DEV_PATH" -b "$CURRENT_BFB" 2>&1 >/dev/null
print_bfb_file_vers "$CURRENT_BFB" "$DEV_PATH"
}
print_bfb_file_vers () {
# Print versions stored in files.
BFB_PATH="$1"
# Second argument is optional, specifies a display name for the file.
# Defaults to $1.
if [ -n "$2" ]; then
DISPLAY_NAME="$2"
else
DISPLAY_NAME="$BFB_PATH"
fi
echo "--$DISPLAY_NAME"
# Find and print the ATF version
echo BlueField ATF version: "$(strings "$BFB_PATH" | grep -m 1 "(\(release\|debug\))")"
# Keep UEFI version and use it to determine BSP version as well
UEFI_VER="$(strings -el "$BFB_PATH" | grep "BlueField" | cut -d':' -f 2)"
# The UEFI image may be compressed. If it is, decompress before searching
# for version strings
UEFI_IMAGE="$BFB_PATH"
if [ -z "$UEFI_VER" ]; then
mkdir "$TMP_DIR"/uefi
cd "$TMP_DIR"/uefi
mlx-mkbfb -x "$BFB_PATH"
gzipped=$(file dump-bl33-v0 | grep gzip)
if [ -n "$gzipped" ]; then
mv dump-bl33-v0 dump-bl33-v0.gz
gunzip dump-bl33-v0.gz
UEFI_VER="$(strings -el dump-bl33-v0 | grep "BlueField" | cut -d':' -f 2)"
else
echo "$PROGNAME: warn: UEFI image not compressed and no version info"
fi
UEFI_IMAGE=$(pwd)/dump-bl33-v0
cd - >/dev/null
fi
echo BlueField UEFI version: $UEFI_VER
# sed regex needs to be escaped heavily, so in more normal terms:
# (.+\..+\..+).*-[0-9]+-g[0-9a-fA-F]+
# Essentially, match the string as Major.Minor.Patch in front,
# the git describe tag from the back, and anything in the middle.
BSP_MAJOR_MINOR_PATCH="$(echo "$UEFI_VER" | sed 's/\(.\+\..\+\..\+\).*-[0-9]\+-g[0-9a-fA-F]\+/\1/')"
# Find build ID
BUILD_ID="$(strings -el "$UEFI_IMAGE" | grep "BId" | sed "s/^BId//")"
if [ -z "$BUILD_ID" ]; then
echo "$PROGNAME: warn: could not find UEFI build ID (likely bootloader too old, using placeholder value)" >&2
BUILD_ID="$DEFAULT_BUILD_ID"
fi
if [ "$BUILD_ID" = 0 ]; then
echo "$PROGNAME: warn: build id of 0 (likely development image)" >&2
fi
echo BlueField BSP version: ${BSP_MAJOR_MINOR_PATCH}.$BUILD_ID
echo
}
PARSED_OPTIONS=$(getopt -n "$PROGNAME" -o hp:f: -l help,part:,file: -- "$@")
eval set -- "$PARSED_OPTIONS"
PARTLIST=
FILE=
while true
do
case $1 in
-h | --help)
usage
exit 0
;;
-p | --part)
PARTLIST="$2"
shift 2
;;
-f | --file)
FILE="$2"
shift 2
;;
--)
shift
break
;;
esac
done
if [ -n "$FILE" ]; then
print_path_vers $FILE
# File mode, do not print any installation info
exit 0
fi
# Print bootloader versions
if [ -z "$PARTLIST" ]; then
# Identify current primary boot partition and print versions
print_path_vers $(mlxbf-bootctl | grep "primary" | cut -d ' ' -f 2)
else
for part in $(echo $PARTLIST | cut -d"," -f1- --output-delimiter=" "); do
if [ "$part" -ne 0 ] && [ "$part" -ne 1 ]; then
echo "$PROGNAME: err: bad partition $part" >&2
continue
fi
print_path_vers /dev/mmcblk0boot$part
done
fi
# Print BlueField version number if Yocto version file is present
if [ -e "/etc/mlnx-release" ]; then
echo OS Release Version: "$(cat /etc/mlnx-release)"
elif [ -e "/etc/bluefield_version" ]; then
echo Yocto Release Version: "$(cat /etc/bluefield_version)"
else
echo No distribution version file present
fi