# Functions for working with flashrom
#
# Copyright (C) 2015 Patrick "P. J." McDermott
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
flashrom_probe()
{
local board_vendor=''
local board_part=''
local board_found=false
local chip_vendor=''
local chip_device=''
local chip_size=''
local chip_bus=''
local chip_found=false
IFS=''
while read -r line; do
unset IFS
case "${line}" in
'Vendor ID: '*', part ID: '*)
board_vendor="${line%, part ID: *}"
board_vendor="${board_vendor#Vendor ID: }"
board_part="${line#*, part ID: }"
dbg 'Found board:'
dbg ' Vendor: %s' "${board_vendor}"
dbg ' Part: %s' "${board_part}"
board_found=true
;;
'Found '*' flash chip "'*'" ('*' kB, '*').')
if ! ${board_found}; then
err 'Failed to probe board'
return 1
fi
chip_vendor="${line% flash chip *}"
chip_vendor="${line#Found }"
chip_device="${line#* flash chip \"}"
chip_device="${chip_device%\" (*}"
chip_size="${line#* (}"
chip_size="${chip_size% kB, *}"
chip_bus="${line#* kB, }"
chip_bus="${chip_bus%).}"
dbg 'Found chip:'
dbg ' Vendor: %s' "${chip_vendor}"
dbg ' Device: %s' "${chip_device}"
dbg ' Size: %u' "${chip_size}"
dbg ' Bus: %s' "${chip_bus}"
if find_board "${board_vendor}" \
"${board_part}" "${chip_device}"
then
chip_found=true
break
fi
;;
esac
IFS=''
done