From a3a8ca972abf4f66788b14cf65bcbc62d6f6af0c Mon Sep 17 00:00:00 2001 From: "William A. Kennington III" Date: Tue, 12 Oct 2021 23:18:52 -0700 Subject: meta-google: ipmi-fru-sh: Add method for initializing eeproms This makes it possible to create new specifications besides the default mapping of OF name to eeprom path. Right now this provides backward compatability with anything that uses of_name_to_eeprom and only provides a new explicit specifier for that specification. Change-Id: If02d9cb392a48e0698b10644d7ade3220bde3eb5 Signed-off-by: William A. Kennington III --- meta-google/recipes-google/ipmi/ipmi-fru-sh/lib.sh | 30 ++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'meta-google') diff --git a/meta-google/recipes-google/ipmi/ipmi-fru-sh/lib.sh b/meta-google/recipes-google/ipmi/ipmi-fru-sh/lib.sh index 335e0b21c..3ae0f0864 100644 --- a/meta-google/recipes-google/ipmi/ipmi-fru-sh/lib.sh +++ b/meta-google/recipes-google/ipmi/ipmi-fru-sh/lib.sh @@ -42,6 +42,32 @@ of_name_to_eeprom() { echo "$eeproms" } +declare -A IPMI_FRU_EEPROM_FILE=() + +ipmi_fru_alloc() { + local name="$1" + local -n ret="$2" + + # Pick the first free index to return as the allocated entry + for (( ret = 0; ret < "${#IPMI_FRU_EEPROM_FILE[@]}"; ++ret )); do + [ -n "${IPMI_FRU_EEPROM_FILE[@]+1}" ] || break + done + + if [[ "$name" =~ ^of-name:(.*)$ || "$name" =~ ^([^:]*)$ ]]; then + local ofn="${BASH_REMATCH[1]}" + local file + file="$(of_name_to_eeprom "$ofn")" || return + IPMI_FRU_EEPROM_FILE["$ret"]="$file" + else + echo "Invalid IPMI FRU eeprom specification: $name" >&2 + return 1 + fi +} + +ipmi_fru_free() { + unset 'IPMI_FRU_EEPROM_FILE[$1]' +} + checksum() { local -n checksum_arr="$1" local checksum=0 @@ -61,7 +87,7 @@ fix_checksum() { } read_bytes() { - local file="$1" + local file="${IPMI_FRU_EEPROM_FILE["$1"]-$1}" local offset="$2" local size="$3" @@ -71,7 +97,7 @@ read_bytes() { } write_bytes() { - local file="$1" + local file="${IPMI_FRU_EEPROM_FILE["$1"]-$1}" local offset="$2" local -n bytes_arr="$3" -- cgit v1.2.3