blob: 82d07737490fee9676a733b1918cb0dabd1a9c48 [file] [log] [blame]
Tom Hughes32f27062020-06-18 15:23:24 -07001# Copyright 2020 The Chromium OS Authors. All rights reserved.
2# Distributed under the terms of the GNU General Public License v2
3
4# @ECLASS: cros-ec-utils.eclass
5# @MAINTAINER:
6# Chromium OS Firmware Team
7# @BUGREPORTS:
8# Please report bugs via http://crbug.com/new (with label Build)
9# @VCSURL: https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/master/eclass/@ECLASS@
10# @BLURB: helper eclass for building Chromium OS firmware
11# @DESCRIPTION:
12# Common helper functions for working with Chromium OS EC firmware.
13#
14# NOTE: When making changes to this class, make sure to modify all the -9999
15# ebuilds that inherit it (e.g., chromeos-fpmcu-release*) to work around
16# http://crbug.com/220902.
17
18if [[ -z "${_ECLASS_CROS_EC_UTILS}" ]]; then
19_ECLASS_CROS_EC_UTILS="1"
20
21# Check for EAPI 7+.
22case "${EAPI:-0}" in
230|1|2|3|4|5|6) die "unsupported EAPI (${EAPI}) in eclass (${ECLASS})" ;;
24*) ;;
25esac
26
27# @FUNCTION: get_firmware_version
28# @USAGE: <firmware path> <firmware ID field>
29# @INTERNAL
30# @DESCRIPTION:
31# Read the firmware version from the provided file.
32get_firmware_version() {
33 debug-print-function "${FUNCNAME[0]}" "$@"
34
35 local file="${1}"
36 local fw_id_field="${2}"
37 local version_string
38 local -a fmap_fwid
39
40 IFS=" " read -r -a fmap_fwid <<<"$(dump_fmap -p "${file}" "${fw_id_field}" \
41 || die)"
42 # Values in array after running above command:
43 # fmap_fwid[0]="${fw_id_field}"
44 # fmap_fwid[1]=offset
45 # fmap_fwid[2]=size
46 version_string="$(dd bs=1 skip="${fmap_fwid[1]}" \
47 count="${fmap_fwid[2]}" if="${file}" status=none || die)"
48 echo "${version_string}"
49}
50
51# @FUNCTION: get_firmware_rw_version
52# @USAGE: <RW firmware path>
53# @DESCRIPTION:
54# Read the read-write (RW) firmware version from the provided file.
55cros-ec-utils-get_firmware_rw_version() {
56 debug-print-function "${FUNCNAME[0]}" "$@"
57
58 local file="${1}"
59 get_firmware_version "${file}" "RW_FWID"
60}
61
62# @FUNCTION: get_firmware_ro_version
63# @USAGE: <RO firmware path>
64# @DESCRIPTION:
65# Read the read-only (RO) firmware version from the provided file.
66cros-ec-utils-get_firmware_ro_version() {
67 debug-print-function "${FUNCNAME[0]}" "$@"
68
69 local file="${1}"
70 get_firmware_version "${file}" "RO_FRID"
71}
72
73fi # _ECLASS_CROS_EC_UTILS