forked from raspberrypi/rpi-eeprom
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrpi-bootloader-version
More file actions
executable file
·56 lines (41 loc) · 1.5 KB
/
Copy pathrpi-bootloader-version
File metadata and controls
executable file
·56 lines (41 loc) · 1.5 KB
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
#!/bin/sh
# Display the running Raspberry Pi bootloader version.
#
# Reads the version information from device-tree to avoid adding a dependency on
# vcgencmd for bootloader updates.
set -e
EXIT_SUCCESS=0
EXIT_FAILED=2
# Location of the bootloader properties exported by the firmware via device-tree.
DT_BOOTLOADER=${DT_BOOTLOADER:-/proc/device-tree/chosen/bootloader}
die() {
echo "$@" >&2
exit ${EXIT_FAILED}
}
# Read a big-endian device-tree integer property as a decimal number.
readDtInt() {
printf "%d" "0x$(od "$1" -v -An -t x1 | tr -d ' \n')"
}
if [ ! -d "${DT_BOOTLOADER}" ]; then
die "Bootloader version not available via device-tree (${DT_BOOTLOADER} not found)."
fi
build_ts_file="${DT_BOOTLOADER}/build-timestamp"
[ -f "${build_ts_file}" ] || die "${build_ts_file} not found."
build_ts=$(readDtInt "${build_ts_file}")
# First line is the build date in UTC.
date -u -d "@${build_ts}" "+%Y/%m/%d %H:%M:%S"
# The version property is the bootloader git hash. The build variant (e.g.
# "release") is not exported via device-tree; released images are always
# "release" builds.
if [ -f "${DT_BOOTLOADER}/version" ]; then
echo "version $(strings "${DT_BOOTLOADER}/version") (release)"
fi
echo "timestamp ${build_ts}"
if [ -f "${DT_BOOTLOADER}/update-timestamp" ]; then
echo "update-time $(readDtInt "${DT_BOOTLOADER}/update-timestamp")"
fi
if [ -f "${DT_BOOTLOADER}/capabilities" ]; then
printf "capabilities 0x%08x\n" "$(readDtInt "${DT_BOOTLOADER}/capabilities")"
fi
echo ""
exit ${EXIT_SUCCESS}